示例#1
0
def run_normal_tests(args, tests):
    test_cmd = get_platform_cmd_prefix()
    if args.runtime:
        test_cmd.append(args.runtime)
    test_cmd.extend([args.engine, '--call-on-exit', '__checkAsync'])

    total = len(tests)
    tested = 0
    passed = 0
    for test in tests:
        tested += 1
        test_path = os.path.relpath(test)
        is_expected_to_fail = os.path.join(os.path.sep, 'fail', '') in test
        (returncode, stdout) = execute_test_command(test_cmd + [test])

        if (returncode == 0 and not is_expected_to_fail) or (returncode == 1 and is_expected_to_fail):
            passed += 1
            if not args.quiet:
                passed_string = 'PASS' + (' (XFAIL)' if is_expected_to_fail else '')
                util.print_test_result(tested, total, True, passed_string, test_path)
        else:
            passed_string = 'FAIL%s (%d)' % (' (XPASS)' if returncode == 0 and is_expected_to_fail else '', returncode)
            util.print_test_result(tested, total, False, passed_string, test_path)
            print("================================================")
            print(stdout)
            print("================================================")

    return passed
def check_temperature_values_are_ordered(args):
    global VERDICT, OUTPUT
    values = []
    poll_time = 5
    timeout = poll_time * 2 + 5
    p = 0.95
    if order == -1:
        p = 1.05
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    for event in events:
        values.append(event['data']['temperature'])
    if are_values_ordered(values, order):
        message = "Temperature value " + order_s + "d"
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        message = "Sensor values were not ordered"
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
示例#3
0
def check_proximity_uncovered_sensor():
    global VERDICT, OUTPUT
    print "Enter 'END' to stop the record"
    executorPoll = ExecutePoll()
    executorPoll.id = sensor_id
    executorPoll.type = sensor_type
    executorPoll.axes = "distance"
    executorPoll.start()
    index = 0
    while (True):
        input_line = raw_input("")
        if input_line == "":
            if (index % 2) == 0:
                expected_values_uncovered.append(float(0))
            else:
                expected_values_uncovered.append(float(1))
            index = index + 1
        elif input_line == "END":
            executorPoll.stop()
            ver, OUTPUT = executorPoll.check_values_uncovered()
            print_test_result(ver, OUTPUT)
            if ver:
                VERDICT = SUCCESS
            else:
                VERDICT = FAILURE
            break
        else:
            print "Unknown command " + input_line + "list of recongised commands : 'ENTER', END"
示例#4
0
def check_light_value_is_0(args):
    global VERDICT, OUTPUT
    values = []
    poll_time = 3
    timeout = poll_time * 2 + 5
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    is_passed = True
    for event in events:
        values.append(event['data']['light'])
        if event['data']['light'] != 0.0:
            is_passed = False
            break
    if is_passed:
        message = "All light values were 0"
        print_test_result(True, OUTPUT)
        VERDICT = SUCCESS
    else:
        message = "It was expected that the sensor would record only 0 values. " +\
            "Returned values were: {}".format(values)
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
示例#5
0
def run_snapshot_tests(args, tests):
    execute_snapshot_cmd = get_platform_cmd_prefix()
    generate_snapshot_cmd = get_platform_cmd_prefix()
    if args.runtime:
        execute_snapshot_cmd.append(args.runtime)
        generate_snapshot_cmd.append(args.runtime)

    execute_snapshot_cmd.extend([args.engine, '--exec-snapshot', 'js.snapshot'])
    execute_snapshot_cmd.extend(['--call-on-exit', '__checkAsync'])

    # engine: jerry[.exe] -> snapshot generator: jerry-snapshot[.exe]
    engine = os.path.splitext(args.engine)
    generate_snapshot_cmd.append(engine[0] + '-snapshot' + engine[1])
    generate_snapshot_cmd.append('generate')

    total = len(tests)
    tested = 0
    passed = 0
    for test in tests:
        tested += 1
        test_path = os.path.relpath(test)
        is_expected_to_fail = os.path.join(os.path.sep, 'fail', '') in test
        (returncode, stdout) = execute_test_command(generate_snapshot_cmd + [test])

        if (returncode == 0) or (returncode == 1 and is_expected_to_fail):
            if not args.quiet:
                passed_string = 'PASS' + (' (XFAIL)' if returncode else '')
                util.print_test_result(tested, total, True, passed_string, test_path, True)
        else:
            util.print_test_result(tested, total, False, 'FAIL (%d)' % (returncode), test_path, True)
            print("================================================")
            print(stdout)
            print("================================================")

        if returncode:
            if is_expected_to_fail:
                passed += 1
            continue

        (returncode, stdout) = execute_test_command(execute_snapshot_cmd)
        os.remove('js.snapshot')

        if (returncode == 0 and not is_expected_to_fail) or (returncode == 1 and is_expected_to_fail):
            passed += 1
            if not args.quiet:
                passed_string = 'PASS' + (' (XFAIL)' if is_expected_to_fail else '')
                util.print_test_result(tested, total, True, passed_string, test_path, False)
        else:
            passed_string = 'FAIL%s (%d)' % (' (XPASS)' if returncode == 0 and is_expected_to_fail else '', returncode)
            util.print_test_result(tested, total, False, passed_string, test_path, False)
            print("================================================")
            print(stdout)
            print("================================================")

    return passed
示例#6
0
def check_light_values_are_ordered(args):
    global VERDICT, OUTPUT
    values = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    for event in events:
        values.append(event['data']['light'])
    if are_values_ordered(values, order):
        OUTPUT = "Light value " + order_s + "d"
        print_test_result(True, OUTPUT)
        VERDICT = SUCCESS
    else:
        OUTPUT = "Sensor values were not ordered"
        print_test_result(False, OUTPUT)
        VERDICT = FAILURE
def check_gyro_when_rotating(args):
    global VERDICT, OUTPUT
    print "Press ENTER to stop the record"
    executorPoll = ExecutePoll()
    executorPoll.id = sensor_id
    executorPoll.type = sensor_type
    executorPoll.axes = AXIS
    executorPoll.start()
    while (True):
        input_line = raw_input("")
        if input_line == "":
            executorPoll.stop()
            ver, OUTPUT = executorPoll.check_values()
            print_test_result(ver, OUTPUT)
            if ver:
                VERDICT = SUCCESS
            else:
                VERDICT = FAILURE
            break
def check_acc_values_are_increasing(args):
    global VERDICT, OUTPUT
    values = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 15, timeout, poll_time)
            if len(events) > 0:
                break
            else:
                OUTPUT = "No data results from sensor poll"
                print_test_result(False, OUTPUT)
                VERDICT = FAILURE
                return
    for event in events:
        values.append(event['data'][axis])
    maxim = max(values)
    max_position = get_value_position(maxim, values)
    if max_position > 3 and are_values_ordered(values[:max_position + 1]) and \
        maxim - values[0] > 0.5 * G:
        message = "Accelerometer values on {} axis were increasing".format(axis)
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        values = eliminate_succesive_duplicates(values)
        message = "It was expected an increasing of the values on the {} axis with at least 0.5 * G.".format(axis)
        message += " Returned values were: {}".format(values)
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
def check_acc_coords_reach_4G(args):
    global VERDICT, OUTPUT
    values = []
    poll_time = 3
    # an approximation for 4G
    acc = 39
    timeout = poll_time * 2 + 5
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            if len(events) > 0:
                break
            else:
                print_test_result(False, "No data results from sensor poll")
                VERDICT = FAILURE
                return
    for event in events:
        values.append(event['data'][AXIS])
    max_value = max(values)
    message = "max value expected over {} axis: {}, obtained max value: {}"
    message = message.format(AXIS, acc, max_value)
    if max_value > acc:
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
示例#10
0
def check_light_value_is_max(args):
    global VERDICT, OUTPUT
    values = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    for event in events:
        values.append(event['data']['light'])
    mean_value = numpy.mean(values)
    relative_standard_deviation = numpy.std(values) / mean_value
    message = "desired_value: {}, obtained average: {}, relative standard deviation: {}"
    message = message.format(sensor_max_value, mean_value, relative_standard_deviation)
    if 0.95 * sensor_max_value < mean_value < 1.05 * sensor_max_value and \
                    relative_standard_deviation < 0.05:
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
示例#11
0
def main(args):
    util.setup_stdio()
    unittests = get_unittests(args.path)
    total = len(unittests)
    if total == 0:
        print("%s: no unit-* test to execute", args.path)
        return 1

    test_cmd = [args.runtime] if args.runtime else []

    tested = 0
    passed = 0
    failed = 0
    for test in unittests:
        tested += 1
        test_path = os.path.relpath(test)
        try:
            subprocess.check_output(test_cmd + [test],
                                    stderr=subprocess.STDOUT,
                                    universal_newlines=True)
            passed += 1
            if not args.quiet:
                util.print_test_result(tested, total, True, 'PASS', test_path)
        except subprocess.CalledProcessError as err:
            failed += 1
            util.print_test_result(tested, total, False,
                                   'FAIL (%d)' % err.returncode, test_path)
            print("================================================")
            print(err.output)
            print("================================================")

    util.print_test_summary(os.path.join(os.path.relpath(args.path), "unit-*"),
                            total, passed, failed)

    if failed > 0:
        return 1
    return 0
def check_acc_coords(args):
    global VERDICT, OUTPUT
    acc_values = {}
    for axis in axes:
        acc_values[axis] = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            if len(events) > 0:
                break
            else:
                OUTPUT = "No data results from sensor poll"
                print_test_result(False, OUTPUT)
                VERDICT = FAILURE
                return
    for event in events:
        for axis in axes:
            acc_values[axis].append(event['data'][axis])
    expected_avg = {}
    axis_avg = {}
    axis_sd = {}
    for axis in axes:
        expected_avg[axis] = 0.0
        axis_avg[axis] = numpy.mean(acc_values[axis])
        axis_sd[axis] = numpy.std(acc_values[axis])
    expected_avg[AXIS_ORIENTATION] = G
    message = ""
    axis_message = "{} axis expected value: {}, , obtained average: {}  standard deviation: {}\n"
    for axis in axes:
        message += axis_message.format(axis, expected_avg[axis],
                                       axis_avg[axis], axis_sd[axis])
    if check_values(axis_avg, axis_sd, expected_avg):
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
示例#13
0
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
'''
import sys
from sensors_util import get_sensor_hal_info
from util import print_test_result
from util import exit_test

arg = sys.argv
try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
    resolution = sensor_info["resolution"]
except:
    print_test_result(False, "Sensor was not found")
    exit_test()

reference = arg[2]
if resolution >= float(reference):
    print_test_result(True, "Resolution is greater than " + reference)
else:
    print_test_result(False, "Resolution is less than " + reference)
示例#14
0
            "Returned values were: {}".format(values)
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message


# test execution
VERDICT = FAILURE
OUTPUT = ""
COMP_CONF = TC_PARAMETERS('COMP_CONF')
COMP_CONF = COMP_CONF[1:-1]

try:
    sensor_info = get_sensor_hal_info(COMP_CONF)
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
except:
    OUTPUT = "Sensor was not found"
    print_test_result(False, OUTPUT)
    exit_test()

menu_items = [
    "Press enter when you are ready to begin the test", {
        "Put the device in a no light environment": check_light_value_is_0
    }, {
        "Do you want repeat the test (y/n)": validate_result
    }
]

menu(menu_items, menu_items[1:])
示例#15
0
import sys
from sensors_util import get_sensor_hal_info
from sensors_util import poll_for_events
from sensors_util import get_axis_values
from sensors_util import is_sd_as_expected
from util import print_test_result
from util import exit_test

arg = sys.argv

try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
except:
    print_test_result(False, "Sensor was not found")
    exit_test()

axis = arg[2]
sensor_freq = 1000000 / sensor_info["maxDelay"]
poll_time = 3
timeout = poll_time * 2 + 5
events_list = poll_for_events(sensor_id, sensor_freq, timeout, poll_time)

if (len(events_list) > 0):
    values = get_axis_values(axis, events_list, sensor_type)
    result = is_sd_as_expected(values)
    print_test_result(result["test_passed"], result["message"])
else:
    print_test_result(False, "Poll exceeded the timeout")
示例#16
0
from display_util import get_display_info
from display_util import get_desc_info
from util import print_test_result
from util import exit_test

arg = sys.argv
accepted_error = 0.001
try:
    desc_info = None
    display_info = None
    info_string = arg[1]
    info_name = arg[2]

    desc_info = get_desc_info(info_string, info_name)
    if desc_info is None:
        print_test_result(False,
                          "Information could not be found in the desc file")
    else:
        display_info = get_display_info()
        if display_info is None or info_name not in display_info.keys():
            print_test_result(False,
                              "Information could not be found by the driver")
        else:
            display_info = display_info[info_name]
            message = "Expected " + info_name + ": " + str(desc_info) + \
                      ", obtained " + info_name + ": " + str(display_info)
            print_test_result(
                abs(float(display_info) - float(desc_info)) < accepted_error,
                message)

except Exception as e:
    print_test_result(False, "Some information could not be found")
示例#17
0
from sensors_util import sens2_out
from util import print_test_result
from util import exit_test

arg = sys.argv

poll_time = 35
timeout = poll_time * 3 + 5

try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]

except Exception:
    print_test_result(False, "Sensor was not found")
    exit_test()

delay = sensor_info["minDelay"]
sensor_frequency = 1000000.00 / delay

cmd = ['adb', 'shell', 'sens2', 'poll', str(sensor_id)]
aux_proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
proc = subprocess.Popen(['tee', sens2_out],
                        stdin=aux_proc.stdout,
                        stdout=subprocess.PIPE)
timeout = 20
timer = Timer(timeout, aux_proc.kill)
timer.start()
timestamp_vector = []
示例#18
0
    limitations under the License.
'''

import sys
from sensors_util import get_sensor_hal_info
from sensors_util import poll_for_events
from util import print_test_result
from util import exit_test

arg = sys.argv
try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
except:
    print_test_result(False, "Sensor was not found")
    exit_test()

poll_seconds = 3
timeout = poll_seconds * 2 + 5
events_list = poll_for_events(str(sensor_id), 0, timeout, poll_seconds)
if (len(events_list) > 0):
    passed = True
    message = "There were recorded only 0 values for all of the gyroscope axes"
    unverified_events = len(events_list)
    for event in events_list:
        if event['data']['x'] != 0 or event['data']['y'] != 0 or event['data'][
                'z'] != 0:
            passed = False
            message = "It was expected that the sensor would record only 0 values for the three axes. "
            message += "This is the recorded data for one of the events: (x: {}, y: {}, z: {})"
示例#19
0
import sys
import math
import os
from sensors_util import get_sensor_hal_info
from util import print_test_result
from util import exit_test
arg = sys.argv
try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
    resolution = sensor_info["resolution"]
    max_value = sensor_info['maxValue']
    min_value = sensor_info['minValue']
except:
    print_test_result(False, "Sensor was not found")
    exit_test()

power = arg[2]
if resolution == 0:
    print_test_result(False, "Resolution should not be 0")
    exit_test()

result = max_value / (resolution * math.pow(2, int(power)))
if int(power) == 8:
    if result >= 1:
        print_test_result(True, "Resolution is greater than 8bit")
    else:
        print_test_result(False, "Resolution is less than 8bit")
if int(power) == 12:
    if result >= 1 and result < 2:
示例#20
0
import sys
import os
import numpy
from sensors_util import poll_for_events
from sensors_util import get_sensor_hal_info
from util import print_test_result
from util import exit_test

arg = sys.argv
try:
    sensor_info = get_sensor_hal_info(arg[1])
    sensor_id = sensor_info["index"]
    sensor_type = sensor_info["type"]
except:
    print_test_result(False, "Sensor was not found")
    exit_test()

min_temp = arg[2]
max_temp = arg[3]
poll_seconds = 5
timeout = poll_seconds * 2 + 5
events_list = poll_for_events(sensor_id, 0, timeout, poll_seconds)
if (len(events_list) > 0):
    values = []
    for event in events_list:
        if event['type'] == sensor_type:
            values.append(event["data"]["temperature"])
    if len(values) > 0:
        mean_value = numpy.mean(values)
        relative_standard_deviation = numpy.std(values) / mean_value
示例#21
0
    events = []
    index = 0
    for line in iter(proc.stdout.readline, ''):
        parsed_json = json.loads(line.rstrip())
        events.append(parsed_json)
        index = index + 1
        if index >= nr_events:
            if timer.is_alive():
                timer.cancel()
            proc.kill()
            return events
    return events


try:
    events = poll_for_events()
    if len(events) < expected_nr_events:
        print_test_result(False, "Timeout excedeed")
    else:
        period_values = []
        # get periods array in seconds
        for event in events[1:]:
            period_values.append(event["event vsync"]["period"] / 1000)
        result = is_frequency_in_expected_range(expected_frequency,
                                                period_values)
        print_test_result(result["test_passed"], result["message"])
except Exception as e:
    print_to_console_and_logcat(str(e))
    print_test_result(False, "Vsync poll could not be realised")
    exit_test()