diff options
Diffstat (limited to 'cts')
39 files changed, 0 insertions, 2777 deletions
diff --git a/cts/README b/cts/README deleted file mode 100644 index 3a22e9846f..0000000000 --- a/cts/README +++ /dev/null @@ -1,6 +0,0 @@ -The first time you use this with a particular th, -connect only th and run ./cts/cts.py --th from -the ec directory. - -Then connect both boards and you can run -./cts/cts to flash both boards.
\ No newline at end of file diff --git a/cts/build.mk b/cts/build.mk deleted file mode 100644 index 817b69b25c..0000000000 --- a/cts/build.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -*- makefile -*- -# Copyright 2016 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -CFLAGS_CTS=-DCTS_MODULE=$(EMPTY) -DCTS_TASKFILE=cts.tasklist - -ifeq "$(CTS_MODULE)" "gpio" -CFLAGS_CTS+=-DCTS_MODULE_GPIO=$(EMPTY) -endif - -ifeq "$(CTS_MODULE)" "i2c" -CFLAGS_CTS+=-DCTS_MODULE_I2C=$(EMPTY) -CONFIG_I2C=y -ifneq ($(BOARD),stm32l476g-eval) -CONFIG_I2C_CONTROLLER=y -endif -endif - -cts-y+=common/cts_common.o - -ifeq ($(BOARD),stm32l476g-eval) - cts-y+=$(CTS_MODULE)/th.o - cts-y+=common/th_common.o -else - cts-y+=$(CTS_MODULE)/dut.o - cts-y+=common/dut_common.o -endif diff --git a/cts/common/__init__.py b/cts/common/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/cts/common/__init__.py +++ /dev/null diff --git a/cts/common/board.py b/cts/common/board.py deleted file mode 100644 index d2c8e02b04..0000000000 --- a/cts/common/board.py +++ /dev/null @@ -1,388 +0,0 @@ -# Copyright 2016 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -# -# Ignore indention messages, since legacy scripts use 2 spaces instead of 4. -# pylint: disable=bad-indentation,docstring-section-indent -# pylint: disable=docstring-trailing-quotes - -# Note: This is a py2/3 compatible file. - -from __future__ import print_function - -from abc import ABCMeta -from abc import abstractmethod -import os -import shutil -import subprocess as sp -import serial - -import six - - -OCD_SCRIPT_DIR = '/usr/share/openocd/scripts' -OPENOCD_CONFIGS = { - 'stm32l476g-eval': 'board/stm32l4discovery.cfg', - 'nucleo-f072rb': 'board/st_nucleo_f0.cfg', - 'nucleo-f411re': 'board/st_nucleo_f4.cfg', -} -FLASH_OFFSETS = { - 'stm32l476g-eval': '0x08000000', - 'nucleo-f072rb': '0x08000000', - 'nucleo-f411re': '0x08000000', -} -REBOOT_MARKER = 'UART initialized after reboot' - - -def get_subprocess_args(): - if six.PY3: - return {'encoding': 'utf-8'} - return {} - - -class Board(six.with_metaclass(ABCMeta, object)): - """Class representing a single board connected to a host machine. - - Attributes: - board: String containing actual type of board, i.e. nucleo-f072rb - config: Directory of board config file relative to openocd's - scripts directory - hla_serial: String containing board's hla_serial number (if board - is an stm32 board) - tty_port: String that is the path to the tty port which board's - UART outputs to - tty: String of file descriptor for tty_port - """ - - def __init__(self, board, module, hla_serial=None): - """Initializes a board object with given attributes. - - Args: - board: String containing board name - module: String of the test module you are building, - i.e. gpio, timer, etc. - hla_serial: Serial number if board's adaptor is an HLA - - Raises: - RuntimeError: Board is not supported - """ - if board not in OPENOCD_CONFIGS: - msg = 'OpenOcd configuration not found for ' + board - raise RuntimeError(msg) - if board not in FLASH_OFFSETS: - msg = 'Flash offset not found for ' + board - raise RuntimeError(msg) - self.board = board - self.flash_offset = FLASH_OFFSETS[self.board] - self.openocd_config = OPENOCD_CONFIGS[self.board] - self.module = module - self.hla_serial = hla_serial - self.tty_port = None - self.tty = None - - def reset_log_dir(self): - """Reset log directory.""" - if os.path.isdir(self.log_dir): - shutil.rmtree(self.log_dir) - os.makedirs(self.log_dir) - - @staticmethod - def get_stlink_serials(): - """Gets serial numbers of all st-link v2.1 board attached to host. - - Returns: - List of serials - """ - usb_args = ['sudo', 'lsusb', '-v', '-d', '0x0483:0x374b'] - st_link_info = sp.check_output(usb_args, **get_subprocess_args()) - st_serials = [] - for line in st_link_info.split('\n'): - if 'iSerial' not in line: - continue - words = line.split() - if len(words) <= 2: - continue - st_serials.append(words[2].strip()) - return st_serials - - @abstractmethod - def get_serial(self): - """Subclass should implement this.""" - pass - - def send_openocd_commands(self, commands): - """Send a command to the board via openocd. - - Args: - commands: A list of commands to send - - Returns: - True if execution is successful or False otherwise. - """ - args = ['sudo', 'openocd', '-s', OCD_SCRIPT_DIR, - '-f', self.openocd_config, '-c', 'hla_serial ' + self.hla_serial] - - for cmd in commands: - args += ['-c', cmd] - args += ['-c', 'shutdown'] - - rv = 1 - with open(self.openocd_log, 'a') as output: - rv = sp.call(args, stdout=output, stderr=sp.STDOUT) - - if rv != 0: - self.dump_openocd_log() - - return rv == 0 - - def dump_openocd_log(self): - with open(self.openocd_log) as log: - print(log.read()) - - def build(self, ec_dir): - """Builds test suite module for board. - - Args: - ec_dir: String of the ec directory path - - Returns: - True if build is successful or False otherwise. - """ - cmds = ['make', - '--directory=' + ec_dir, - 'BOARD=' + self.board, - 'CTS_MODULE=' + self.module, - '-j'] - - rv = 1 - with open(self.build_log, 'a') as output: - rv = sp.call(cmds, stdout=output, stderr=sp.STDOUT) - - if rv != 0: - self.dump_build_log() - - return rv == 0 - - def dump_build_log(self): - with open(self.build_log) as log: - print(log.read()) - - def flash(self, image_path): - """Flashes board with most recent build ec.bin.""" - cmd = ['reset_config connect_assert_srst', - 'init', - 'reset init', - 'flash write_image erase %s %s' % (image_path, self.flash_offset)] - return self.send_openocd_commands(cmd) - - def to_string(self): - s = ('Type: Board\n' - 'board: ' + self.board + '\n' - 'hla_serial: ' + self.hla_serial + '\n' - 'openocd_config: ' + self.openocd_config + '\n' - 'tty_port: ' + self.tty_port + '\n' - 'tty: ' + str(self.tty) + '\n') - return s - - def reset_halt(self): - """Reset then halt board.""" - return self.send_openocd_commands(['init', 'reset halt']) - - def resume(self): - """Resume halting board.""" - return self.send_openocd_commands(['init', 'resume']) - - def setup_tty(self): - """Call this before calling read_tty for the first time. - - This is not in the initialization because caller only should call - this function after serial numbers are setup - """ - self.get_serial() - self.reset_halt() - self.identify_tty_port() - - tty = None - try: - tty = serial.Serial(self.tty_port, 115200, timeout=1) - except serial.SerialException: - raise ValueError('Failed to open ' + self.tty_port + ' of ' + self.board + - '. Please make sure the port is available and you have' + - ' permission to read it. Create dialout group and run:' + - ' sudo usermod -a -G dialout <username>.') - self.tty = tty - - def read_tty(self, max_boot_count=1): - """Read info from a serial port described by a file descriptor. - - Args: - max_boot_count: Stop reading if boot count exceeds this number - - Returns: - result: characters read from tty - boot: boot counts - """ - buf = [] - line = [] - boot = 0 - while True: - c = self.tty.read().decode('utf-8') - if not c: - break - line.append(c) - if c == '\n': - l = ''.join(line) - buf.append(l) - if REBOOT_MARKER in l: - boot += 1 - line = [] - if boot > max_boot_count: - break - - l = ''.join(line) - buf.append(l) - result = ''.join(buf) - - return result, boot - - def identify_tty_port(self): - """Saves this board's serial port.""" - dev_dir = '/dev' - id_prefix = 'ID_SERIAL_SHORT=' - com_devices = [f for f in os.listdir(dev_dir) if f.startswith('ttyACM')] - - for device in com_devices: - self.tty_port = os.path.join(dev_dir, device) - properties = sp.check_output( - ['udevadm', 'info', '-a', '-n', self.tty_port, '--query=property'], - **get_subprocess_args()) - for line in [l.strip() for l in properties.split('\n')]: - if line.startswith(id_prefix): - if self.hla_serial == line[len(id_prefix):]: - return - - # If we get here without returning, something is wrong - raise RuntimeError('The device dev path could not be found') - - def close_tty(self): - """Close tty.""" - self.tty.close() - - -class TestHarness(Board): - """Subclass of Board representing a Test Harness. - - Attributes: - serial_path: Path to file containing serial number - """ - - def __init__(self, board, module, log_dir, serial_path): - """Initializes a board object with given attributes. - - Args: - board: board name - module: module name - log_dir: Directory where log file is stored - serial_path: Path to file containing serial number - """ - Board.__init__(self, board, module) - self.log_dir = log_dir - self.openocd_log = os.path.join(log_dir, 'openocd_th.log') - self.build_log = os.path.join(log_dir, 'build_th.log') - self.serial_path = serial_path - self.reset_log_dir() - - def get_serial(self): - """Loads serial number from saved location.""" - if self.hla_serial: - return # serial was already loaded - try: - with open(self.serial_path, mode='r') as f: - s = f.read() - self.hla_serial = s.strip() - return - except IOError: - msg = ('Your TH board has not been identified.\n' - 'Connect only TH and run the script --setup, then try again.') - raise RuntimeError(msg) - - def save_serial(self): - """Saves the TH serial number to a file.""" - serials = Board.get_stlink_serials() - if len(serials) > 1: - msg = ('There are more than one test board connected to the host.' - '\nConnect only the test harness and remove other boards.') - raise RuntimeError(msg) - if len(serials) < 1: - msg = ('No test boards were found.\n' - 'Check boards are connected.') - raise RuntimeError(msg) - - s = serials[0] - serial_dir = os.path.dirname(self.serial_path) - if not os.path.exists(serial_dir): - os.makedirs(serial_dir) - with open(self.serial_path, mode='w') as f: - f.write(s) - self.hla_serial = s - - print('Your TH serial', s, 'has been saved as', self.serial_path) - return - - -class DeviceUnderTest(Board): - """Subclass of Board representing a DUT board. - - Attributes: - th: Reference to test harness board to which this DUT is attached - """ - - def __init__(self, board, th, module, log_dir, hla_ser=None): - """Initializes a DUT object. - - Args: - board: String containing board name - th: Reference to test harness board to which this DUT is attached - module: module name - log_dir: Directory where log file is stored - hla_ser: Serial number if board uses an HLA adaptor - """ - Board.__init__(self, board, module, hla_serial=hla_ser) - self.th = th - self.log_dir = log_dir - self.openocd_log = os.path.join(log_dir, 'openocd_dut.log') - self.build_log = os.path.join(log_dir, 'build_dut.log') - self.reset_log_dir() - - def get_serial(self): - """Get serial number. - - Precondition: The DUT and TH must both be connected, and th.hla_serial - must hold the correct value (the th's serial #) - - Raises: - RuntimeError: DUT isn't found or multiple DUTs are found. - """ - if self.hla_serial is not None: - # serial was already set ('' is a valid serial) - return - - serials = Board.get_stlink_serials() - dut = [s for s in serials if self.th.hla_serial != s] - - # If len(dut) is 0 then your dut doesn't use an st-link device, so we - # don't have to worry about its serial number - if not dut: - msg = ('Failed to find serial for DUT.\n' - 'Is ' + self.board + ' connected?') - raise RuntimeError(msg) - if len(dut) > 1: - msg = ('Found multiple DUTs.\n' - 'You can connect only one DUT at a time. This may be caused by\n' - 'an incorrect TH serial. Check if ' + self.th.serial_path + '\n' - 'contains a correct serial.') - raise RuntimeError(msg) - - # Found your other st-link device serial! - self.hla_serial = dut[0] - return diff --git a/cts/common/cts.rc b/cts/common/cts.rc deleted file mode 100644 index 264b982655..0000000000 --- a/cts/common/cts.rc +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * This file is included by cts_common.h as an enumeration of error codes, - * as well as being processed by cts.py to get error code names. The format - * must be either of the followings: - * - * CTS_RC_<NAME>, - * CTS_RC_<NAME> = X, - * - * where <NAME> will be printed on the result screen. - */ - -/* - * Host only return codes. Should not be needed by th.c or dut.c. - */ -/* Test didn't run */ -CTS_RC_DID_NOT_START = -1, -/* Test didn't end */ -CTS_RC_DID_NOT_END = -2, -/* Results were reported twice or more */ -CTS_RC_DUPLICATE_RUN = -3, -/* Error in parsing return code. Probably it was null or not an integer. */ -CTS_RC_INVALID_RC = -4, - -/* - * Regular return codes. Used by DUT and TH. - */ -CTS_RC_SUCCESS = 0, -CTS_RC_FAILURE, -CTS_RC_BAD_SYNC, -CTS_RC_TIMEOUT, diff --git a/cts/common/cts_common.c b/cts/common/cts_common.c deleted file mode 100644 index 8975636655..0000000000 --- a/cts/common/cts_common.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2017 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "console.h" -#include "cts_common.h" - -__attribute__((weak)) void clean_state(void) -{ - /* Each test overrides as needed */ -} - -void cts_main_loop(const struct cts_test* tests, const char *name) -{ - enum cts_rc rc; - int i; - - cflush(); - for (i = 0; i < cts_test_count; i++) { - CPRINTF("\n%s start\n", tests[i].name); - cflush(); - clean_state(); - sync(); - rc = tests[i].run(); - CPRINTF("\n%s end %d\n", tests[i].name, rc); - cflush(); - } - - CPRINTS("%s test suite finished", name); -} diff --git a/cts/common/cts_common.h b/cts/common/cts_common.h deleted file mode 100644 index 13a435e655..0000000000 --- a/cts/common/cts_common.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef __CTS_COMMON_H -#define __CTS_COMMON_H - -#include "console.h" - -/* Console output macros */ -#define CPUTS(outstr) cputs(CC_SYSTEM, outstr) -#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) -#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) -#define CPRINTL(format, args...) CPRINTS("%s:%d: "format, \ - __func__, __LINE__, ## args) - -#define READ_WAIT_TIME_MS 100 -#define CTS_INTERRUPT_TRIGGER_DELAY_US (250 * MSEC) - -enum cts_rc { - #include "cts.rc" -}; - -struct cts_test { - enum cts_rc (*run)(void); - char *name; -}; - -extern const int cts_test_count; - -/** - * Main loop where each test in a suite is executed - * - * A test suite can implement its custom loop as needed. - * - * Args: - * @test: List of tests to run - * @name: Name of the test to be printed on EC console - */ -void cts_main_loop(const struct cts_test* tests, const char *name); - -/** - * Callback function called at the beginning of the main loop - */ -void clean_state(void); - -/** - * Synchronize DUT and TH - * - * @return CTS_RC_SUCCESS if sync is successful - */ -enum cts_rc sync(void); - -#endif diff --git a/cts/common/cts_testlist.h b/cts/common/cts_testlist.h deleted file mode 100644 index 1586c1348e..0000000000 --- a/cts/common/cts_testlist.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "util.h" - -/* - * CTS_TEST macro takes the following arguments: - * - * @test: Function running the test - * @th_rc: Expected CTS_RC_* from TH - * @th_string: Expected string printed by TH - * @dut_rc: Expected CTR_RC_* from DUT - * @dut_string: Expected string printed by DUT - * - * CTS_TEST macro is processed in multiple places. One is here for creating - * an array of test functions. Only @test is used. - * - * Another is in cts.py for evaluating the test results against expectations. - */ - -#undef CTS_TEST -#define CTS_TEST(test, th_rc, th_string, dut_rc, dut_string) \ - {test, STRINGIFY(test)}, -struct cts_test tests[] = { -#include "cts.testlist" -}; - -const int cts_test_count = ARRAY_SIZE(tests); diff --git a/cts/common/dut_common.c b/cts/common/dut_common.c deleted file mode 100644 index 6e62a280e2..0000000000 --- a/cts/common/dut_common.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "cts_common.h" -#include "gpio.h" -#include "watchdog.h" - -enum cts_rc sync(void) -{ - int input_level; - - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 0); - do { - watchdog_reload(); - input_level = gpio_get_level(GPIO_HANDSHAKE_INPUT); - } while (!input_level); - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 1); - do { - watchdog_reload(); - input_level = gpio_get_level(GPIO_HANDSHAKE_INPUT); - } while (input_level); - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 0); - - return CTS_RC_SUCCESS; -} - diff --git a/cts/common/th_common.c b/cts/common/th_common.c deleted file mode 100644 index 1d692b7843..0000000000 --- a/cts/common/th_common.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "gpio.h" -#include "timer.h" -#include "watchdog.h" -#include "cts_common.h" - -/* Return SUCCESS if and only if we reach end of function - * Returning success here means sync was successful - */ -enum cts_rc sync(void) -{ - int input_level; - - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 0); - do { - watchdog_reload(); - input_level = gpio_get_level(GPIO_HANDSHAKE_INPUT); - } while (input_level); - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 1); - do { - watchdog_reload(); - input_level = gpio_get_level(GPIO_HANDSHAKE_INPUT); - } while (!input_level); - gpio_set_level(GPIO_HANDSHAKE_OUTPUT, 0); - do { - watchdog_reload(); - input_level = gpio_get_level(GPIO_HANDSHAKE_INPUT); - } while (input_level); - - return CTS_RC_SUCCESS; -} diff --git a/cts/cts.py b/cts/cts.py deleted file mode 100755 index c3e0335cab..0000000000 --- a/cts/cts.py +++ /dev/null @@ -1,443 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2016 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -# -# Ignore indention messages, since legacy scripts use 2 spaces instead of 4. -# pylint: disable=bad-indentation,docstring-section-indent -# pylint: disable=docstring-trailing-quotes - -# A script which builds, flashes, and runs EC CTS -# -# Software prerequisites: -# - openocd version 0.10 or above -# - lsusb -# - udevadm -# -# To try it out, hook two boards (DEFAULT_TH and DEFAULT_DUT) with USB cables -# to the host and execute the script: -# $ ./cts.py -# It'll run mock tests. The result will be stored in CTS_TEST_RESULT_DIR. - -# Note: This is a py2/3 compatible file. - -from __future__ import print_function - -import argparse -import os -import shutil -import time -import common.board as board - - -CTS_RC_PREFIX = 'CTS_RC_' -DEFAULT_TH = 'stm32l476g-eval' -DEFAULT_DUT = 'nucleo-f072rb' -MAX_SUITE_TIME_SEC = 5 -CTS_TEST_RESULT_DIR = '/tmp/ects' - -# Host only return codes. Make sure they match values in cts.rc -CTS_RC_DID_NOT_START = -1 # test did not run. -CTS_RC_DID_NOT_END = -2 # test did not run. -CTS_RC_DUPLICATE_RUN = -3 # test was run multiple times. -CTS_RC_INVALID_RETURN_CODE = -4 # failed to parse return code - - -class Cts(object): - """Class that represents a eCTS run. - - Attributes: - dut: DeviceUnderTest object representing DUT - th: TestHarness object representing a test harness - module: Name of module to build/run tests for - testlist: List of strings of test names contained in given module - return_codes: Dict of strings of return codes, with a code's integer - value being the index for the corresponding string representation - """ - - def __init__(self, ec_dir, th, dut, module): - """Initializes cts class object with given arguments. - - Args: - ec_dir: Path to ec directory - th: Name of the test harness board - dut: Name of the device under test board - module: Name of module to build/run tests for (e.g. gpio, interrupt) - """ - self.results_dir = os.path.join(CTS_TEST_RESULT_DIR, dut, module) - if os.path.isdir(self.results_dir): - shutil.rmtree(self.results_dir) - else: - os.makedirs(self.results_dir) - self.ec_dir = ec_dir - self.module = module - serial_path = os.path.join(CTS_TEST_RESULT_DIR, 'th_serial') - self.th = board.TestHarness(th, module, self.results_dir, serial_path) - self.dut = board.DeviceUnderTest(dut, self.th, module, self.results_dir) - cts_dir = os.path.join(self.ec_dir, 'cts') - testlist_path = os.path.join(cts_dir, self.module, 'cts.testlist') - return_codes_path = os.path.join(cts_dir, 'common', 'cts.rc') - self.get_return_codes(return_codes_path) - self.testlist = self.get_macro_args(testlist_path, 'CTS_TEST') - - def build(self): - """Build images for DUT and TH.""" - print('Building DUT image...') - if not self.dut.build(self.ec_dir): - raise RuntimeError('Building module %s for DUT failed' % (self.module)) - print('Building TH image...') - if not self.th.build(self.ec_dir): - raise RuntimeError('Building module %s for TH failed' % (self.module)) - - def flash_boards(self): - """Flashes TH and DUT with their most recently built ec.bin.""" - cts_module = 'cts_' + self.module - image_path = os.path.join('build', self.th.board, cts_module, 'ec.bin') - self.identify_boards() - print('Flashing TH with', image_path) - if not self.th.flash(image_path): - raise RuntimeError('Flashing TH failed') - image_path = os.path.join('build', self.dut.board, cts_module, 'ec.bin') - print('Flashing DUT with', image_path) - if not self.dut.flash(image_path): - raise RuntimeError('Flashing DUT failed') - - def setup(self): - """Setup boards.""" - self.th.save_serial() - - def identify_boards(self): - """Updates serials of TH and DUT in that order (order matters).""" - self.th.get_serial() - self.dut.get_serial() - - def get_macro_args(self, filepath, macro): - """Get list of args of a macro in a file when macro. - - Args: - filepath: String containing absolute path to the file - macro: String containing text of macro to get args of - - Returns: - List of dictionaries where each entry is: - 'name': Test name, - 'th_string': Expected string from TH, - 'dut_string': Expected string from DUT, - """ - tests = [] - with open(filepath, 'r') as f: - lines = f.readlines() - joined = ''.join(lines).replace('\\\n', '').splitlines() - for l in joined: - if not l.strip().startswith(macro): - continue - d = {} - l = l.strip()[len(macro):] - l = l.strip('()').split(',') - d['name'] = l[0].strip() - d['th_rc'] = self.get_return_code_value(l[1].strip().strip('"')) - d['th_string'] = l[2].strip().strip('"') - d['dut_rc'] = self.get_return_code_value(l[3].strip().strip('"')) - d['dut_string'] = l[4].strip().strip('"') - tests.append(d) - return tests - - def get_return_codes(self, filepath): - """Read return code names from the return code definition file.""" - self.return_codes = {} - val = 0 - with open(filepath, 'r') as f: - for line in f: - line = line.strip() - if not line.startswith(CTS_RC_PREFIX): - continue - line = line.split(',')[0] - if '=' in line: - tokens = line.split('=') - line = tokens[0].strip() - val = int(tokens[1].strip()) - self.return_codes[line] = val - val += 1 - - def parse_output(self, output): - """Parse console output from DUT or TH. - - Args: - output: String containing consoule output - - Returns: - List of dictionaries where each key and value are: - name = 'ects_test_x', - started = True/False, - ended = True/False, - rc = CTS_RC_*, - output = All text between 'ects_test_x start' and 'ects_test_x end' - """ - results = [] - i = 0 - for test in self.testlist: - results.append({}) - results[i]['name'] = test['name'] - results[i]['started'] = False - results[i]['rc'] = CTS_RC_DID_NOT_START - results[i]['string'] = False - results[i]['output'] = [] - i += 1 - - i = 0 - for ln in [ln.strip() for ln in output.split('\n')]: - if i + 1 > len(results): - break - tokens = ln.split() - if len(tokens) >= 2: - if tokens[0].strip() == results[i]['name']: - if tokens[1].strip() == 'start': - # start line found - if results[i]['started']: # Already started - results[i]['rc'] = CTS_RC_DUPLICATE_RUN - else: - results[i]['rc'] = CTS_RC_DID_NOT_END - results[i]['started'] = True - continue - elif results[i]['started'] and tokens[1].strip() == 'end': - # end line found - results[i]['rc'] = CTS_RC_INVALID_RETURN_CODE - if len(tokens) == 3: - try: - results[i]['rc'] = int(tokens[2].strip()) - except ValueError: - pass - # Since index is incremented when 'end' is encountered, we don't - # need to check duplicate 'end'. - i += 1 - continue - if results[i]['started']: - results[i]['output'].append(ln) - - return results - - def get_return_code_name(self, code, strip_prefix=False): - name = '' - for k, v in self.return_codes.items(): - if v == code: - if strip_prefix: - name = k[len(CTS_RC_PREFIX):] - else: - name = k - return name - - def get_return_code_value(self, name): - if name: - return self.return_codes[name] - return 0 - - def evaluate_run(self, dut_output, th_output): - """Parse outputs to derive test results. - - Args: - dut_output: String output of DUT - th_output: String output of TH - - Returns: - th_results: list of test results for TH - dut_results: list of test results for DUT - """ - th_results = self.parse_output(th_output) - dut_results = self.parse_output(dut_output) - - # Search for expected string in each output - for i, v in enumerate(self.testlist): - if v['th_string'] in th_results[i]['output'] or not v['th_string']: - th_results[i]['string'] = True - if v['dut_string'] in dut_results[i]['output'] or not v['dut_string']: - dut_results[i]['string'] = True - - return th_results, dut_results - - def print_result(self, th_results, dut_results): - """Print results to the screen. - - Args: - th_results: list of test results for TH - dut_results: list of test results for DUT - """ - len_test_name = max(len(s['name']) for s in self.testlist) - len_code_name = max(len(self.get_return_code_name(v, True)) - for v in self.return_codes.values()) - - head = '{:^' + str(len_test_name) + '} ' - head += '{:^' + str(len_code_name) + '} ' - head += '{:^' + str(len_code_name) + '}' - head += '{:^' + str(len(' TH_STR')) + '}' - head += '{:^' + str(len(' DUT_STR')) + '}' - head += '{:^' + str(len(' RESULT')) + '}\n' - fmt = '{:' + str(len_test_name) + '} ' - fmt += '{:>' + str(len_code_name) + '} ' - fmt += '{:>' + str(len_code_name) + '}' - fmt += '{:>' + str(len(' TH_STR')) + '}' - fmt += '{:>' + str(len(' DUT_STR')) + '}' - fmt += '{:>' + str(len(' RESULT')) + '}\n' - - self.formatted_results = head.format( - 'TEST NAME', 'TH_RC', 'DUT_RC', - ' TH_STR', ' DUT_STR', ' RESULT') - for i, d in enumerate(dut_results): - th_cn = self.get_return_code_name(th_results[i]['rc'], True) - dut_cn = self.get_return_code_name(dut_results[i]['rc'], True) - th_res = self.evaluate_result(th_results[i], - self.testlist[i]['th_rc'], - self.testlist[i]['th_string']) - dut_res = self.evaluate_result(dut_results[i], - self.testlist[i]['dut_rc'], - self.testlist[i]['dut_string']) - self.formatted_results += fmt.format( - d['name'], th_cn, dut_cn, - 'YES' if th_results[i]['string'] else 'NO', - 'YES' if dut_results[i]['string'] else 'NO', - 'PASS' if th_res and dut_res else 'FAIL') - - def evaluate_result(self, result, expected_rc, expected_string): - if result['rc'] != expected_rc: - return False - if expected_string and expected_string not in result['output']: - return False - return True - - def run(self): - """Resets boards, records test results in results dir.""" - print('Reading serials...') - self.identify_boards() - print('Opening DUT tty...') - self.dut.setup_tty() - print('Opening TH tty...') - self.th.setup_tty() - - # Boards might be still writing to tty. Wait a few seconds before flashing. - time.sleep(3) - - # clear buffers - print('Clearing DUT tty...') - self.dut.read_tty() - print('Clearing TH tty...') - self.th.read_tty() - - # Resets the boards and allows them to run tests - # Due to current (7/27/16) version of sync function, - # both boards must be rest and halted, with the th - # resuming first, in order for the test suite to run in sync - print('Halting TH...') - if not self.th.reset_halt(): - raise RuntimeError('Failed to halt TH') - print('Halting DUT...') - if not self.dut.reset_halt(): - raise RuntimeError('Failed to halt DUT') - print('Resuming TH...') - if not self.th.resume(): - raise RuntimeError('Failed to resume TH') - print('Resuming DUT...') - if not self.dut.resume(): - raise RuntimeError('Failed to resume DUT') - - time.sleep(MAX_SUITE_TIME_SEC) - - print('Reading DUT tty...') - dut_output, _ = self.dut.read_tty() - self.dut.close_tty() - print('Reading TH tty...') - th_output, _ = self.th.read_tty() - self.th.close_tty() - - print('Halting TH...') - if not self.th.reset_halt(): - raise RuntimeError('Failed to halt TH') - print('Halting DUT...') - if not self.dut.reset_halt(): - raise RuntimeError('Failed to halt DUT') - - if not dut_output or not th_output: - raise ValueError('Output missing from boards. If you have a process ' - 'reading ttyACMx, please kill that process and try ' - 'again.') - - print('Pursing results...') - th_results, dut_results = self.evaluate_run(dut_output, th_output) - - # Print out results - self.print_result(th_results, dut_results) - - # Write results - dest = os.path.join(self.results_dir, 'results.log') - with open(dest, 'w') as fl: - fl.write(self.formatted_results) - - # Write UART outputs - dest = os.path.join(self.results_dir, 'uart_th.log') - with open(dest, 'w') as fl: - fl.write(th_output) - dest = os.path.join(self.results_dir, 'uart_dut.log') - with open(dest, 'w') as fl: - fl.write(dut_output) - - print(self.formatted_results) - - # TODO(chromium:735652): Should set exit code for the shell - - -def main(): - ec_dir = os.path.realpath(os.path.join( - os.path.dirname(os.path.abspath(__file__)), '..')) - os.chdir(ec_dir) - - dut = DEFAULT_DUT - module = 'meta' - - parser = argparse.ArgumentParser(description='Used to build/flash boards') - parser.add_argument('-d', - '--dut', - help='Specify DUT you want to build/flash') - parser.add_argument('-m', - '--module', - help='Specify module you want to build/flash') - parser.add_argument('-s', - '--setup', - action='store_true', - help='Connect only the TH to save its serial') - parser.add_argument('-b', - '--build', - action='store_true', - help='Build test suite (no flashing)') - parser.add_argument('-f', - '--flash', - action='store_true', - help='Flash boards with most recent images') - parser.add_argument('-r', - '--run', - action='store_true', - help='Run tests without flashing') - - args = parser.parse_args() - - if args.module: - module = args.module - - if args.dut: - dut = args.dut - - cts = Cts(ec_dir, DEFAULT_TH, dut=dut, module=module) - - if args.setup: - cts.setup() - elif args.build: - cts.build() - elif args.flash: - cts.flash_boards() - elif args.run: - cts.run() - else: - cts.build() - cts.flash_boards() - cts.run() - -if __name__ == '__main__': - main() diff --git a/cts/cts.tasklist b/cts/cts.tasklist deleted file mode 100644 index 152b0d02b2..0000000000 --- a/cts/cts.tasklist +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * See CONFIG_TASK_LIST in config.h for details. - */ - -/* Default task list for suites which don't define its own */ -#define CONFIG_CTS_TASK_LIST \ - TASK_ALWAYS(CTS, cts_task, NULL, TASK_STACK_SIZE) diff --git a/cts/gpio/cts.testlist b/cts/gpio/cts.testlist deleted file mode 100644 index 113d2b405f..0000000000 --- a/cts/gpio/cts.testlist +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Test whether sync completes successfully */ -CTS_TEST(sync_test,,,,) - -/* Check if the dut can set a line low */ -CTS_TEST(set_low_test,,,,) - -/* Check if the dut can set a line high */ -CTS_TEST(set_high_test,,,,) - -/* Check if the dut can read a line that is low */ -CTS_TEST(read_high_test,,,,) - -/* Check if the dut can read a line that is high */ -CTS_TEST(read_low_test,,,,) - -/* Check if the dut reads its true pin level (success) - or its register level when configured as a low open drain output pin */ -CTS_TEST(od_read_high_test,,,,) diff --git a/cts/gpio/dut.c b/cts/gpio/dut.c deleted file mode 100644 index 828996db8e..0000000000 --- a/cts/gpio/dut.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "watchdog.h" -#include "uart.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" -#include "cts_common.h" - -enum cts_rc sync_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc set_high_test(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_LOW); - gpio_set_level(GPIO_OUTPUT_TEST, 1); - msleep(READ_WAIT_TIME_MS*2); - return CTS_RC_SUCCESS; -} - -enum cts_rc set_low_test(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_LOW); - gpio_set_level(GPIO_OUTPUT_TEST, 0); - msleep(READ_WAIT_TIME_MS*2); - return CTS_RC_SUCCESS; -} - -enum cts_rc read_high_test(void) -{ - int level; - - gpio_set_flags(GPIO_INPUT_TEST, GPIO_INPUT | GPIO_PULL_UP); - msleep(READ_WAIT_TIME_MS); - level = gpio_get_level(GPIO_INPUT_TEST); - if (level) - return CTS_RC_SUCCESS; - else - return CTS_RC_FAILURE; -} - -enum cts_rc read_low_test(void) -{ - int level; - - gpio_set_flags(GPIO_INPUT_TEST, GPIO_INPUT | GPIO_PULL_UP); - msleep(READ_WAIT_TIME_MS); - level = gpio_get_level(GPIO_INPUT_TEST); - if (!level) - return CTS_RC_SUCCESS; - else - return CTS_RC_FAILURE; -} - -enum cts_rc od_read_high_test(void) -{ - int level; - - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_HIGH | GPIO_PULL_UP); - msleep(READ_WAIT_TIME_MS); - level = gpio_get_level(GPIO_OUTPUT_TEST); - if (!level) - return CTS_RC_SUCCESS; - else - return CTS_RC_FAILURE; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "GPIO"); - task_wait_event(-1); -} diff --git a/cts/gpio/th.c b/cts/gpio/th.c deleted file mode 100644 index 6c628b0ad5..0000000000 --- a/cts/gpio/th.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "watchdog.h" -#include "uart.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" -#include "cts_common.h" - -enum cts_rc sync_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc set_high_test(void) -{ - int level; - - gpio_set_flags(GPIO_INPUT_TEST, GPIO_INPUT | GPIO_PULL_UP); - msleep(READ_WAIT_TIME_MS); - level = gpio_get_level(GPIO_INPUT_TEST); - if (level) - return CTS_RC_SUCCESS; - else - return CTS_RC_FAILURE; -} - -enum cts_rc set_low_test(void) -{ - int level; - - gpio_set_flags(GPIO_INPUT_TEST, GPIO_INPUT | GPIO_PULL_UP); - msleep(READ_WAIT_TIME_MS); - level = gpio_get_level(GPIO_INPUT_TEST); - if (!level) - return CTS_RC_SUCCESS; - else - return CTS_RC_FAILURE; -} - -enum cts_rc read_high_test(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_LOW); - gpio_set_level(GPIO_OUTPUT_TEST, 1); - msleep(READ_WAIT_TIME_MS*2); - return CTS_RC_SUCCESS; -} - -enum cts_rc read_low_test(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_LOW); - gpio_set_level(GPIO_OUTPUT_TEST, 0); - msleep(READ_WAIT_TIME_MS*2); - return CTS_RC_SUCCESS; -} - -enum cts_rc od_read_high_test(void) -{ - gpio_set_flags(GPIO_INPUT_TEST, GPIO_OUTPUT | GPIO_ODR_LOW); - msleep(READ_WAIT_TIME_MS*2); - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "GPIO"); - task_wait_event(-1); -} diff --git a/cts/hook/cts.testlist b/cts/hook/cts.testlist deleted file mode 100644 index 97b25575d4..0000000000 --- a/cts/hook/cts.testlist +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2017 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test HOOK_INIT - */ -CTS_TEST(test_init_hook,,,,) - -/* - * Test HOOK_TICK and HOOK_SECOND - */ -CTS_TEST(test_ticks,,,,) - -/* - * Test hook priority - */ -CTS_TEST(test_priority,,,,) - -/* - * Test deferred calls - */ -CTS_TEST(test_deferred,,,,)
\ No newline at end of file diff --git a/cts/hook/dut.c b/cts/hook/dut.c deleted file mode 100644 index f3a52ddaf4..0000000000 --- a/cts/hook/dut.c +++ /dev/null @@ -1,165 +0,0 @@ -/* Copyright 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Test hooks. - */ - -#include "common.h" -#include "console.h" -#include "cts_common.h" -#include "hooks.h" -#include "task.h" -#include "timer.h" -#include "util.h" -#include "watchdog.h" - -static int init_hook_count; -static int tick_hook_count; -static int tick2_hook_count; -static int tick_count_seen_by_tick2; -static timestamp_t tick_time[2]; -static int second_hook_count; -static timestamp_t second_time[2]; -static int deferred_call_count; - -static void init_hook(void) -{ - init_hook_count++; -} -DECLARE_HOOK(HOOK_INIT, init_hook, HOOK_PRIO_DEFAULT); - -static void tick_hook(void) -{ - tick_hook_count++; - tick_time[0] = tick_time[1]; - tick_time[1] = get_time(); -} -DECLARE_HOOK(HOOK_TICK, tick_hook, HOOK_PRIO_DEFAULT); - -static void tick2_hook(void) -{ - tick2_hook_count++; - tick_count_seen_by_tick2 = tick_hook_count; -} -/* tick2_hook() prio means it should be called after tick_hook() */ -DECLARE_HOOK(HOOK_TICK, tick2_hook, HOOK_PRIO_DEFAULT + 1); - -static void second_hook(void) -{ - second_hook_count++; - second_time[0] = second_time[1]; - second_time[1] = get_time(); -} -DECLARE_HOOK(HOOK_SECOND, second_hook, HOOK_PRIO_DEFAULT); - -static void deferred_func(void) -{ - deferred_call_count++; -} -DECLARE_DEFERRED(deferred_func); - -static void invalid_deferred_func(void) -{ - deferred_call_count++; -} - -static const struct deferred_data invalid_deferred_func_data = { - invalid_deferred_func -}; - -static enum cts_rc test_init_hook(void) -{ - if (init_hook_count != 1) - return CTS_RC_FAILURE; - return CTS_RC_SUCCESS; -} - -static enum cts_rc test_ticks(void) -{ - int64_t interval; - int error_pct; - - /* - * HOOK_SECOND must have been fired at least once when HOOK - * task starts. We only need to wait for just more than a second - * to allow it fires for the second time. - */ - msleep(1300); - - interval = tick_time[1].val - tick_time[0].val; - error_pct = (interval - HOOK_TICK_INTERVAL) * 100 / - HOOK_TICK_INTERVAL; - if (error_pct < -10 || 10 < error_pct) { - CPRINTS("tick error=%d%% interval=%lld", error_pct, interval); - return CTS_RC_FAILURE; - } - - interval = second_time[1].val - second_time[0].val; - error_pct = (interval - SECOND) * 100 / SECOND; - if (error_pct < -10 || 10 < error_pct) { - CPRINTS("second error=%d%% interval=%lld", error_pct, interval); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -static enum cts_rc test_priority(void) -{ - usleep(HOOK_TICK_INTERVAL); - if (tick_hook_count != tick2_hook_count) - return CTS_RC_FAILURE; - if (tick_hook_count != tick_count_seen_by_tick2) - return CTS_RC_FAILURE; - return CTS_RC_SUCCESS; -} - -static enum cts_rc test_deferred(void) -{ - deferred_call_count = 0; - hook_call_deferred(&deferred_func_data, 50 * MSEC); - if (deferred_call_count != 0) { - CPRINTL("deferred_call_count=%d", deferred_call_count); - return CTS_RC_FAILURE; - } - msleep(100); - if (deferred_call_count != 1) { - CPRINTL("deferred_call_count=%d", deferred_call_count); - return CTS_RC_FAILURE; - } - - /* Test cancellation */ - deferred_call_count = 0; - hook_call_deferred(&deferred_func_data, 50 * MSEC); - msleep(25); - hook_call_deferred(&deferred_func_data, -1); - msleep(75); - if (deferred_call_count != 0) { - CPRINTL("deferred_call_count=%d", deferred_call_count); - return CTS_RC_FAILURE; - } - - /* Invalid deferred function */ - deferred_call_count = 0; - if (hook_call_deferred(&invalid_deferred_func_data, 50 * MSEC) - == EC_SUCCESS) { - CPRINTL("non_deferred_func_data"); - return CTS_RC_FAILURE; - } - msleep(100); - if (deferred_call_count != 0) { - CPRINTL("deferred_call_count=%d", deferred_call_count); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "Hook"); - task_wait_event(-1); -} diff --git a/cts/hook/th.c b/cts/hook/th.c deleted file mode 120000 index 41eab28462..0000000000 --- a/cts/hook/th.c +++ /dev/null @@ -1 +0,0 @@ -dut.c
\ No newline at end of file diff --git a/cts/i2c/cts.testlist b/cts/i2c/cts.testlist deleted file mode 100644 index 7b6461e84d..0000000000 --- a/cts/i2c/cts.testlist +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test i2c write for 8, 16, and 32 bits. DUT runs as a master and TH - * runs as a slave. - */ -CTS_TEST(write8_test,,,,) -CTS_TEST(write16_test,,,,) -CTS_TEST(write32_test,,,,) - -/* - * Test i2c read for 8, 16, and 32 bits. DUT runs as a master and TH - * runs as a slave. You need external pull-ups (10 kohms) on SDL and SDA - * to make read16_test and read32_test pass. - */ -CTS_TEST(read8_test,,,,) -CTS_TEST(read16_test,,,,) -CTS_TEST(read32_test,,,,)
\ No newline at end of file diff --git a/cts/i2c/cts_i2c.h b/cts/i2c/cts_i2c.h deleted file mode 100644 index 2914d92a99..0000000000 --- a/cts/i2c/cts_i2c.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -enum cts_i2c_packets { - WRITE8_OFF, - WRITE16_OFF, - WRITE32_OFF, - READ8_OFF, - READ16_OFF, - READ32_OFF, -}; - -#define WRITE8_DATA 0x42 -#define WRITE16_DATA 0x1234 -#define WRITE32_DATA 0xDEADBEEF -#define READ8_DATA 0x23 -#define READ16_DATA 0xACED -#define READ32_DATA 0x01ABCDEF diff --git a/cts/i2c/dut.c b/cts/i2c/dut.c deleted file mode 100644 index c7a3f9fccf..0000000000 --- a/cts/i2c/dut.c +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "cts_i2c.h" -#include "i2c.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "uart.h" -#include "watchdog.h" - -#define TH_ADDR_FLAGS 0x1e - -enum cts_rc write8_test(void) -{ - if (i2c_write8(i2c_ports[0].port, TH_ADDR_FLAGS, - WRITE8_OFF, WRITE8_DATA)) - return CTS_RC_FAILURE; - return CTS_RC_SUCCESS; -} - -enum cts_rc write16_test(void) -{ - if (i2c_write16(i2c_ports[0].port, TH_ADDR_FLAGS, - WRITE16_OFF, WRITE16_DATA)) - return CTS_RC_FAILURE; - return CTS_RC_SUCCESS; -} - -enum cts_rc write32_test(void) -{ - if (i2c_write32(i2c_ports[0].port, TH_ADDR_FLAGS, - WRITE32_OFF, WRITE32_DATA)) - return CTS_RC_FAILURE; - return CTS_RC_SUCCESS; -} - -enum cts_rc read8_test(void) -{ - int data; - - if (i2c_read8(i2c_ports[0].port, TH_ADDR_FLAGS, - READ8_OFF, &data)) - return CTS_RC_FAILURE; - if (data != READ8_DATA) { - CPRINTL("Expecting 0x%x but read 0x%x", READ8_DATA, data); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc read16_test(void) -{ - int data; - - if (i2c_read16(i2c_ports[0].port, TH_ADDR_FLAGS, - READ16_OFF, &data)) - return CTS_RC_FAILURE; - if (data != READ16_DATA) { - CPRINTL("Expecting 0x%x but read 0x%x", READ16_DATA, data); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc read32_test(void) -{ - int data; - - if (i2c_read32(i2c_ports[0].port, TH_ADDR_FLAGS, - READ32_OFF, &data)) - return CTS_RC_FAILURE; - if (data != READ32_DATA) { - CPRINTL("Read 0x%x expecting 0x%x", data, READ32_DATA); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "I2C"); - task_wait_event(-1); -} diff --git a/cts/i2c/th.c b/cts/i2c/th.c deleted file mode 100644 index 78035cb1b2..0000000000 --- a/cts/i2c/th.c +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <string.h> -#include "common.h" -#include "cts_common.h" -#include "cts_i2c.h" -#include "i2c.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "uart.h" -#include "watchdog.h" - -static uint8_t inbox[I2C_MAX_HOST_PACKET_SIZE + 2]; -static char data_received; - -void i2c_data_received(int port, uint8_t *buf, int len) -{ - memcpy(inbox, buf, len); - data_received = 1; -} - -/* CTS I2C protocol implementation */ -int i2c_set_response(int port, uint8_t *buf, int len) -{ - switch (buf[0]) { - case READ8_OFF: - buf[0] = READ8_DATA; - return 1; - case READ16_OFF: - buf[0] = READ16_DATA & 0xFF; - buf[1] = (READ16_DATA >> 8) & 0xFF; - return 2; - case READ32_OFF: - buf[0] = READ32_DATA & 0xFF; - buf[1] = (READ32_DATA >> 8) & 0xFF; - buf[2] = (READ32_DATA >> 16) & 0xFF; - buf[3] = (READ32_DATA >> 24) & 0xFF; - return 4; - default: - return 0; - } -} - -static int wait_for_in_flag(uint32_t timeout_ms) -{ - uint64_t start_time, end_time; - - start_time = get_time().val; - end_time = start_time + timeout_ms * 1000; - - while (get_time().val < end_time) { - if (data_received) - return 0; - msleep(5); - watchdog_reload(); - } - return 1; -} - -void clean_state(void) -{ - memset(inbox, 0, sizeof(inbox)); - data_received = 0; -} - -enum cts_rc write8_test(void) -{ - int in; - - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != WRITE8_OFF) - return CTS_RC_FAILURE; - in = inbox[1]; - if (in != WRITE8_DATA) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -enum cts_rc write16_test(void) -{ - int in; - - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != WRITE16_OFF) - return CTS_RC_FAILURE; - in = inbox[2] << 8 | inbox[1] << 0; - if (in != WRITE16_DATA) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -enum cts_rc write32_test(void) -{ - int in; - - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != WRITE32_OFF) - return CTS_RC_FAILURE; - in = inbox[4] << 24 | inbox[3] << 16 | inbox[2] << 8 | inbox[1]; - if (in != WRITE32_DATA) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -enum cts_rc read8_test(void) -{ - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != READ8_OFF) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -enum cts_rc read16_test(void) -{ - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != READ16_OFF) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -enum cts_rc read32_test(void) -{ - if (wait_for_in_flag(100)) - return CTS_RC_TIMEOUT; - if (inbox[0] != READ32_OFF) - return CTS_RC_FAILURE; - - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "I2C"); - task_wait_event(-1); -} diff --git a/cts/interrupt/cts.testlist b/cts/interrupt/cts.testlist deleted file mode 100644 index 0fdaf6fca2..0000000000 --- a/cts/interrupt/cts.testlist +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Test interrupt_enable/disable */ -CTS_TEST(test_interrupt_enable,,,,) -CTS_TEST(test_interrupt_disable,,,,) - -/* Test task_wait_for_event */ -CTS_TEST(test_task_wait_event,,,,) - -/* Test task_disable_irq */ -CTS_TEST(test_task_disable_irq,,,,) - -/* Test nested interrupt. Lower priority IRQ is fired, followed by - * higher priority IRQ. Handler executions should be nested. - * - * P1 *-----* - * / \ - * P2 *----* *----* - * / \ - * task_cts ----* *---- - * A B C D - */ -CTS_TEST(test_nested_interrupt_low_high,,,,) - -/* Test nested interrupt. Higher priority IRQ is fired, followed by - * lower priority IRQ. Handlers should be executed sequentially. - * - * P1 *-----* - * / \ - * P2 / *-----* - * / \ - * task_cts ----* *---- - * B C A D - */ -CTS_TEST(test_nested_interrupt_high_low,,,,) - -/* - * Other ideas - * - * Test back-to-back interrupts, NVIC, Priorities - */
\ No newline at end of file diff --git a/cts/interrupt/dut.c b/cts/interrupt/dut.c deleted file mode 100644 index 3c83e5701f..0000000000 --- a/cts/interrupt/dut.c +++ /dev/null @@ -1,184 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <string.h> -#include "common.h" -#include "cts_common.h" -#include "gpio.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" - -static int got_interrupt; -static int wake_me_up; -static int state_index; -static char state[4]; - -/* - * Raw busy loop. Returns 1 if loop finishes before interrupt is triggered. - * Loop length is controlled by busy_loop_timeout. It has to be set to the - * value which makes the loop last longer than CTS_INTERRUPT_TRIGGER_DELAY_US. - */ -static int busy_loop(void) -{ - /* TODO: Derive a proper value from clock speed */ - const uint32_t busy_loop_timeout = 0xfffff; - uint32_t counter = 0; - - while (counter++ < busy_loop_timeout) { - if (got_interrupt) - break; - watchdog_reload(); - } - if (counter > busy_loop_timeout) - return 1; - - return 0; -} - -/* - * Interrupt handler. - */ -void cts_irq1(enum gpio_signal signal) -{ - state[state_index++] = 'B'; - - got_interrupt = in_interrupt_context(); - - /* Wake up the CTS task */ - if (wake_me_up) - task_wake(TASK_ID_CTS); - - busy_loop(); - - state[state_index++] = 'C'; -} - -void cts_irq2(enum gpio_signal signal) -{ - state[state_index++] = 'A'; - busy_loop(); - state[state_index++] = 'D'; -} - -void clean_state(void) -{ - uint32_t *event; - - interrupt_enable(); - got_interrupt = 0; - wake_me_up = 0; - state_index = 0; - memset(state, '_', sizeof(state)); - event = task_get_event_bitmap(TASK_ID_CTS); - *event = 0; -} - -enum cts_rc test_task_wait_event(void) -{ - uint32_t event; - - wake_me_up = 1; - - /* Sleep and wait for interrupt. This shouldn't time out. */ - event = task_wait_event(CTS_INTERRUPT_TRIGGER_DELAY_US * 2); - if (event != TASK_EVENT_WAKE) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - if (!got_interrupt) { - CPRINTS("Interrupt context not detected"); - return CTS_RC_TIMEOUT; - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc test_task_disable_irq(void) -{ - uint32_t event; - - wake_me_up = 1; - - task_disable_irq(CTS_IRQ_NUMBER); - /* Sleep and wait for interrupt. This should time out. */ - event = task_wait_event(CTS_INTERRUPT_TRIGGER_DELAY_US * 2); - if (event != TASK_EVENT_TIMER) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - task_enable_irq(CTS_IRQ_NUMBER); - - return CTS_RC_SUCCESS; -} - -enum cts_rc test_interrupt_enable(void) -{ - if (busy_loop()) { - CPRINTS("Timeout before interrupt"); - return CTS_RC_TIMEOUT; - } - return CTS_RC_SUCCESS; -} - -enum cts_rc test_interrupt_disable(void) -{ - interrupt_disable(); - if (!busy_loop()) { - CPRINTS("Expected timeout but didn't"); - return CTS_RC_FAILURE; - } - return CTS_RC_SUCCESS; -} - -enum cts_rc test_nested_interrupt_low_high(void) -{ - uint32_t event; - - event = task_wait_event(CTS_INTERRUPT_TRIGGER_DELAY_US * 4); - if (event != TASK_EVENT_TIMER) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - if (!got_interrupt) { - CPRINTS("Interrupt context not detected"); - return CTS_RC_TIMEOUT; - } - if (memcmp(state, "ABCD", sizeof(state))) { - CPRINTS("State transition differs from expectation"); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc test_nested_interrupt_high_low(void) -{ - uint32_t event; - - event = task_wait_event(CTS_INTERRUPT_TRIGGER_DELAY_US * 4); - if (event != TASK_EVENT_TIMER) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - - if (memcmp(state, "BCAD", sizeof(state))) { - CPRINTS("State transition differs from expectation"); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - gpio_enable_interrupt(GPIO_CTS_IRQ1); - gpio_enable_interrupt(GPIO_CTS_IRQ2); - cts_main_loop(tests, "Interrupt"); - task_wait_event(-1); -} diff --git a/cts/interrupt/th.c b/cts/interrupt/th.c deleted file mode 100644 index 1639a1868c..0000000000 --- a/cts/interrupt/th.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "gpio.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" - -void clean_state(void) -{ - gpio_set_level(GPIO_OUTPUT_TEST, 1); - gpio_set_level(GPIO_CTS_IRQ2, 1); -} - -static void trigger_interrupt1(void) -{ - usleep(CTS_INTERRUPT_TRIGGER_DELAY_US); - gpio_set_level(GPIO_OUTPUT_TEST, 0); - usleep(CTS_INTERRUPT_TRIGGER_DELAY_US); -} - -static void trigger_interrupt2(void) -{ - usleep(CTS_INTERRUPT_TRIGGER_DELAY_US); - gpio_set_level(GPIO_CTS_IRQ2, 0); - usleep(CTS_INTERRUPT_TRIGGER_DELAY_US); -} - -enum cts_rc test_task_wait_event(void) -{ - trigger_interrupt1(); - return CTS_RC_SUCCESS; -} - -enum cts_rc test_task_disable_irq(void) -{ - trigger_interrupt1(); - return CTS_RC_SUCCESS; -} - -enum cts_rc test_interrupt_enable(void) -{ - trigger_interrupt1(); - return CTS_RC_SUCCESS; -} - -enum cts_rc test_interrupt_disable(void) -{ - trigger_interrupt1(); - return CTS_RC_SUCCESS; -} - -enum cts_rc test_nested_interrupt_low_high(void) -{ - trigger_interrupt2(); - trigger_interrupt1(); - return CTS_RC_SUCCESS; -} - -enum cts_rc test_nested_interrupt_high_low(void) -{ - trigger_interrupt1(); - trigger_interrupt2(); - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_HIGH); - cts_main_loop(tests, "Interrupt"); - task_wait_event(-1); -} diff --git a/cts/meta/cts.testlist b/cts/meta/cts.testlist deleted file mode 100644 index 28ac7e325f..0000000000 --- a/cts/meta/cts.testlist +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test SUCCESS from both TH and DUT - */ -CTS_TEST(success_test,,,,) - -/* - * Test FAILURE from DUT - */ -CTS_TEST(fail_dut_test,,, CTS_RC_FAILURE,) - -/* - * Test FAILURE from TH - */ -CTS_TEST(fail_th_test, CTS_RC_FAILURE,,,) - -/* - * Test failure from both TH and DUT. - */ -CTS_TEST(fail_both_test, CTS_RC_FAILURE,, CTS_RC_FAILURE,) - -/* - * Test bad sync for TH - */ -CTS_TEST(bad_sync_test, CTS_RC_BAD_SYNC,,,) - -/* - * Test should fail with bad sync. - */ -CTS_TEST(bad_sync_both_test, CTS_RC_BAD_SYNC,, CTS_RC_BAD_SYNC,) - -/* - * Test hang on DUT - */ -CTS_TEST(hang_test, CTS_RC_SUCCESS,, CTS_RC_DID_NOT_END,) - -/* - * Test CTS_RC_DID_NOT_START - * - * Since the previous test hung on DUT, this test won't run on DUT. - * TH will wait forever in sync(), thus won't end. - */ - CTS_TEST(did_not_start_test, CTS_RC_DID_NOT_END,, CTS_RC_DID_NOT_START,) - -/* - * TODO: Add test for expected string - * TODO: Make sync() return CTS_RC_BAD_SYNC when it times out. - */
\ No newline at end of file diff --git a/cts/meta/dut.c b/cts/meta/dut.c deleted file mode 100644 index c321676aec..0000000000 --- a/cts/meta/dut.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "task.h" -#include "timer.h" -#include "uart.h" -#include "watchdog.h" - -enum cts_rc success_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc fail_dut_test(void) -{ - return CTS_RC_FAILURE; -} - -enum cts_rc fail_th_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc fail_both_test(void) -{ - return CTS_RC_FAILURE; -} - -enum cts_rc bad_sync_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc bad_sync_both_test(void) -{ - return CTS_RC_BAD_SYNC; -} - -enum cts_rc hang_test(void) -{ - while (1) { - watchdog_reload(); - sleep(1); - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc did_not_start_test(void) -{ - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "Meta"); - task_wait_event(-1); -} diff --git a/cts/meta/th.c b/cts/meta/th.c deleted file mode 100644 index 57b2f492bd..0000000000 --- a/cts/meta/th.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "task.h" -#include "timer.h" -#include "uart.h" -#include "watchdog.h" - -enum cts_rc success_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc fail_dut_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc fail_th_test(void) -{ - return CTS_RC_FAILURE; -} - -enum cts_rc fail_both_test(void) -{ - return CTS_RC_FAILURE; -} - -enum cts_rc bad_sync_test(void) -{ - return CTS_RC_BAD_SYNC; -} - -enum cts_rc bad_sync_both_test(void) -{ - return CTS_RC_BAD_SYNC; -} - -enum cts_rc hang_test(void) -{ - return CTS_RC_SUCCESS; -} - -enum cts_rc did_not_start_test(void) -{ - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "Meta"); - task_wait_event(-1); -} diff --git a/cts/mutex/cts.tasklist b/cts/mutex/cts.tasklist deleted file mode 100644 index 3387e1de09..0000000000 --- a/cts/mutex/cts.tasklist +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * See CONFIG_TASK_LIST in config.h for details. - */ -#define CONFIG_CTS_TASK_LIST \ - TASK_ALWAYS(MTX3C, mutex_random_task, NULL, 384) \ - TASK_ALWAYS(MTX3B, mutex_random_task, NULL, 384) \ - TASK_ALWAYS(MTX3A, mutex_random_task, NULL, 384) \ - TASK_ALWAYS(MTX2, mutex_second_task, NULL, 384) \ - TASK_ALWAYS(CTS, cts_task, NULL, TASK_STACK_SIZE) diff --git a/cts/mutex/cts.testlist b/cts/mutex/cts.testlist deleted file mode 100644 index 5b1cdb1dae..0000000000 --- a/cts/mutex/cts.testlist +++ /dev/null @@ -1,9 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test mutex lock and unlock - */ -CTS_TEST(lock_unlock_test,,,,)
\ No newline at end of file diff --git a/cts/mutex/dut.c b/cts/mutex/dut.c deleted file mode 100644 index 9cbbd8badb..0000000000 --- a/cts/mutex/dut.c +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * Copyright 2011 Google Inc. - * - * Tasks for mutexes basic tests. - */ - -#include "console.h" -#include "common.h" -#include "cts_common.h" -#include "task.h" -#include "test_util.h" -#include "timer.h" -#include "util.h" - -static struct mutex mtx; - -/* period between 50us and 3.2ms */ -#define PERIOD_US(num) (((num % 64) + 1) * 50) -/* one of the 3 MTX3x tasks */ -#define RANDOM_TASK(num) (TASK_ID_MTX3C + (num % 3)) - -int mutex_random_task(void *unused) -{ - char letter = 'A'+(TASK_ID_MTX3A - task_get_current()); - /* wait to be activated */ - - while (1) { - task_wait_event(0); - ccprintf("%c+\n", letter); - mutex_lock(&mtx); - ccprintf("%c=\n", letter); - task_wait_event(0); - ccprintf("%c-\n", letter); - mutex_unlock(&mtx); - } - - task_wait_event(0); - - return EC_SUCCESS; -} - -int mutex_second_task(void *unused) -{ - task_id_t id = task_get_current(); - - ccprintf("\n[Mutex second task %d]\n", id); - - task_wait_event(0); - ccprintf("MTX2: locking..."); - mutex_lock(&mtx); - ccprintf("done\n"); - task_wake(TASK_ID_CTS); - ccprintf("MTX2: unlocking...\n"); - mutex_unlock(&mtx); - - task_wait_event(0); - - return EC_SUCCESS; -} - -static enum cts_rc lock_unlock_test(void) -{ - task_id_t id = task_get_current(); - uint32_t rdelay = (uint32_t)0x0bad1dea; - uint32_t rtask = (uint32_t)0x1a4e1dea; - int i; - - ccprintf("\n[Mutex main task %d]\n", id); - - /* --- Lock/Unlock without contention --- */ - ccprintf("No contention :"); - mutex_lock(&mtx); - mutex_unlock(&mtx); - mutex_lock(&mtx); - mutex_unlock(&mtx); - mutex_lock(&mtx); - mutex_unlock(&mtx); - ccprintf("done.\n"); - - /* --- Serialization to test simple contention --- */ - ccprintf("Simple contention :\n"); - /* lock the mutex from the other task */ - task_set_event(TASK_ID_MTX2, TASK_EVENT_WAKE); - task_wait_event(0); - /* block on the mutex */ - ccprintf("MTX1: blocking...\n"); - mutex_lock(&mtx); - ccprintf("MTX1: get lock\n"); - mutex_unlock(&mtx); - - /* --- mass lock-unlocking from several tasks --- */ - ccprintf("Massive locking/unlocking :\n"); - for (i = 0; i < 500; i++) { - /* Wake up a random task */ - task_wake(RANDOM_TASK(rtask)); - /* next pseudo random delay */ - rtask = prng(rtask); - /* Wait for a "random" period */ - task_wait_event(PERIOD_US(rdelay)); - /* next pseudo random delay */ - rdelay = prng(rdelay); - } - - return EC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - wait_for_task_started(); - cts_main_loop(tests, "Mutex"); - task_wait_event(-1); -} diff --git a/cts/mutex/th.c b/cts/mutex/th.c deleted file mode 100644 index 9cbbd8badb..0000000000 --- a/cts/mutex/th.c +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * Copyright 2011 Google Inc. - * - * Tasks for mutexes basic tests. - */ - -#include "console.h" -#include "common.h" -#include "cts_common.h" -#include "task.h" -#include "test_util.h" -#include "timer.h" -#include "util.h" - -static struct mutex mtx; - -/* period between 50us and 3.2ms */ -#define PERIOD_US(num) (((num % 64) + 1) * 50) -/* one of the 3 MTX3x tasks */ -#define RANDOM_TASK(num) (TASK_ID_MTX3C + (num % 3)) - -int mutex_random_task(void *unused) -{ - char letter = 'A'+(TASK_ID_MTX3A - task_get_current()); - /* wait to be activated */ - - while (1) { - task_wait_event(0); - ccprintf("%c+\n", letter); - mutex_lock(&mtx); - ccprintf("%c=\n", letter); - task_wait_event(0); - ccprintf("%c-\n", letter); - mutex_unlock(&mtx); - } - - task_wait_event(0); - - return EC_SUCCESS; -} - -int mutex_second_task(void *unused) -{ - task_id_t id = task_get_current(); - - ccprintf("\n[Mutex second task %d]\n", id); - - task_wait_event(0); - ccprintf("MTX2: locking..."); - mutex_lock(&mtx); - ccprintf("done\n"); - task_wake(TASK_ID_CTS); - ccprintf("MTX2: unlocking...\n"); - mutex_unlock(&mtx); - - task_wait_event(0); - - return EC_SUCCESS; -} - -static enum cts_rc lock_unlock_test(void) -{ - task_id_t id = task_get_current(); - uint32_t rdelay = (uint32_t)0x0bad1dea; - uint32_t rtask = (uint32_t)0x1a4e1dea; - int i; - - ccprintf("\n[Mutex main task %d]\n", id); - - /* --- Lock/Unlock without contention --- */ - ccprintf("No contention :"); - mutex_lock(&mtx); - mutex_unlock(&mtx); - mutex_lock(&mtx); - mutex_unlock(&mtx); - mutex_lock(&mtx); - mutex_unlock(&mtx); - ccprintf("done.\n"); - - /* --- Serialization to test simple contention --- */ - ccprintf("Simple contention :\n"); - /* lock the mutex from the other task */ - task_set_event(TASK_ID_MTX2, TASK_EVENT_WAKE); - task_wait_event(0); - /* block on the mutex */ - ccprintf("MTX1: blocking...\n"); - mutex_lock(&mtx); - ccprintf("MTX1: get lock\n"); - mutex_unlock(&mtx); - - /* --- mass lock-unlocking from several tasks --- */ - ccprintf("Massive locking/unlocking :\n"); - for (i = 0; i < 500; i++) { - /* Wake up a random task */ - task_wake(RANDOM_TASK(rtask)); - /* next pseudo random delay */ - rtask = prng(rtask); - /* Wait for a "random" period */ - task_wait_event(PERIOD_US(rdelay)); - /* next pseudo random delay */ - rdelay = prng(rdelay); - } - - return EC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - wait_for_task_started(); - cts_main_loop(tests, "Mutex"); - task_wait_event(-1); -} diff --git a/cts/task/cts.tasklist b/cts/task/cts.tasklist deleted file mode 100644 index 6477d74c2c..0000000000 --- a/cts/task/cts.tasklist +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * See CONFIG_TASK_LIST in config.h for details. - */ -#define CONFIG_CTS_TASK_LIST \ - TASK_ALWAYS(A, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(B, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(C, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(TICK, task_tick, NULL, 256) \ - TASK_ALWAYS(CTS, cts_task, NULL, TASK_STACK_SIZE) diff --git a/cts/task/cts.testlist b/cts/task/cts.testlist deleted file mode 100644 index c4b7bc3231..0000000000 --- a/cts/task/cts.testlist +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test task switching. Task A wakes up B and goes to sleep. Task B wakes - * up C then goes to sleep. Task C wakes up A then goes to sleep. This is - * repeated TEST_COUNT times. It's expected all tasks to run exactly - * TEST_COUNT times. Tick task runs to inject some irregularity. - */ -CTS_TEST(test_task_switch,,,,) - -/* - * Test task priority. CTS task wakes up A and C then goes to sleep. Since C - * has a higher priority, C should run first. This should result in C running - * one more time than A (or B). - */ -CTS_TEST(test_task_priority,,,,) - -/* - * Test stack overflow. CTS task overflows the stack and it should be detected - * when task switch happens. Reboot is expected. - */ -CTS_TEST(test_stack_overflow,\ - CTS_RC_DID_NOT_END, "Stack overflow in CTS task!",\ - CTS_RC_DID_NOT_END, "Stack overflow in CTS task!") diff --git a/cts/task/dut.c b/cts/task/dut.c deleted file mode 100644 index 71fe4050ec..0000000000 --- a/cts/task/dut.c +++ /dev/null @@ -1,144 +0,0 @@ -/* Copyright 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Tasks for scheduling test. - */ - -#include "common.h" -#include "cts_common.h" -#include "task.h" -#include "timer.h" - -static int repeat_count; -static int wake_count[3]; - -void clean_state(void) -{ - wake_count[0] = wake_count[1] = wake_count[2] = 0; -} - -void task_abc(void *data) -{ - int task_id = task_get_current(); - int id = task_id - TASK_ID_A; - task_id_t next = task_id + 1; - - if (next > TASK_ID_C) - next = TASK_ID_A; - - task_wait_event(-1); - - CPRINTS("%c Starting", 'A' + id); - cflush(); - - while (1) { - wake_count[id]++; - if (id == 2 && wake_count[id] == repeat_count) { - task_set_event(TASK_ID_CTS, TASK_EVENT_WAKE); - task_wait_event(0); - } else { - task_set_event(next, TASK_EVENT_WAKE); - task_wait_event(0); - } - } -} - -void task_tick(void *data) -{ - task_wait_event(-1); - ccprintf("\n[starting Task T]\n"); - - /* Wake up every tick */ - while (1) - /* Wait for timer interrupt message */ - usleep(3000); -} - -enum cts_rc test_task_switch(void) -{ - uint32_t event; - - repeat_count = 3000; - - task_wake(TASK_ID_A); - event = task_wait_event(5 * SECOND); - - if (event != TASK_EVENT_WAKE) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - - if (wake_count[0] != repeat_count || wake_count[1] != repeat_count) { - CPRINTS("Unexpected counter values: %d %d %d", - wake_count[0], wake_count[1], wake_count[2]); - return CTS_RC_FAILURE; - } - - /* TODO: Verify no tasks are ready, no events are pending. */ - if (*task_get_event_bitmap(TASK_ID_A) - || *task_get_event_bitmap(TASK_ID_B) - || *task_get_event_bitmap(TASK_ID_C)) { - CPRINTS("Events are pending"); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -enum cts_rc test_task_priority(void) -{ - uint32_t event; - - repeat_count = 2; - - task_wake(TASK_ID_A); - task_wake(TASK_ID_C); - - event = task_wait_event(5 * SECOND); - - if (event != TASK_EVENT_WAKE) { - CPRINTS("Woken up by unexpected event: 0x%08x", event); - return CTS_RC_FAILURE; - } - - if (wake_count[0] != repeat_count - 1 - || wake_count[1] != repeat_count - 1) { - CPRINTS("Unexpected counter values: %d %d %d", - wake_count[0], wake_count[1], wake_count[2]); - return CTS_RC_FAILURE; - } - - /* TODO: Verify no tasks are ready, no events are pending. */ - if (*task_get_event_bitmap(TASK_ID_A) - || *task_get_event_bitmap(TASK_ID_B) - || *task_get_event_bitmap(TASK_ID_C)) { - CPRINTS("Events are pending"); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -static void recurse(int x) -{ - CPRINTS("+%d", x); - msleep(1); - recurse(x + 1); - CPRINTS("-%d", x); -} - -enum cts_rc test_stack_overflow(void) -{ - recurse(0); - return CTS_RC_FAILURE; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - task_wake(TASK_ID_TICK); - cts_main_loop(tests, "Task"); - task_wait_event(-1); -} diff --git a/cts/task/th.c b/cts/task/th.c deleted file mode 120000 index 41eab28462..0000000000 --- a/cts/task/th.c +++ /dev/null @@ -1 +0,0 @@ -dut.c
\ No newline at end of file diff --git a/cts/timer/cts.testlist b/cts/timer/cts.testlist deleted file mode 100644 index 9b5da0d6c9..0000000000 --- a/cts/timer/cts.testlist +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * Test timer accuracy - * - * After sync, DUT and TH start counting down one second. After one second, - * DUT raises GPIO level, which triggers an interrupt on TH. TH determines - * whether the test passes or not based on how much more or less time elapsed - * than one second. - * - * Requirements: - * - Sync connection - * - GPIO_OUTPUT connection for sending notification from DUT - * - Calibrated TH timer - */ -CTS_TEST(timer_calibration_test,,,,) diff --git a/cts/timer/dut.c b/cts/timer/dut.c deleted file mode 100644 index 96d7c5a3cf..0000000000 --- a/cts/timer/dut.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "gpio.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" - -static enum cts_rc timer_calibration_test(void) -{ - gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_HIGH); - - sync(); - sleep(1); - gpio_set_level(GPIO_OUTPUT_TEST, 0); - - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "Timer"); - task_wait_event(-1); -} diff --git a/cts/timer/th.c b/cts/timer/th.c deleted file mode 100644 index e82cac71ab..0000000000 --- a/cts/timer/th.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright 2016 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "common.h" -#include "cts_common.h" -#include "gpio.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" - -/* - * Interrupt handler - * - * DUT is supposed to trigger an interrupt when it's done counting down, - * causing this function to be invoked. - */ -void cts_irq(enum gpio_signal signal) -{ - /* Wake up the CTS task */ - task_wake(TASK_ID_CTS); -} - -static enum cts_rc timer_calibration_test(void) -{ - /* Error margin: +/-2 msec (0.2% for one second) */ - const int32_t margin = 2 * MSEC; - int32_t elapsed, delta; - timestamp_t t0, t1; - - gpio_enable_interrupt(GPIO_CTS_NOTIFY); - interrupt_enable(); - - sync(); - t0 = get_time(); - /* Wait for interrupt */ - task_wait_event(-1); - t1 = get_time(); - - elapsed = (int32_t)(t1.val - t0.val); - delta = elapsed - SECOND; - if (delta < -margin) { - CPRINTS("DUT clock runs too fast: %+d usec", delta); - return CTS_RC_FAILURE; - } - if (margin < delta) { - CPRINTS("DUT clock runs too slow: %+d usec", delta); - return CTS_RC_FAILURE; - } - - return CTS_RC_SUCCESS; -} - -#include "cts_testlist.h" - -void cts_task(void) -{ - cts_main_loop(tests, "Timer"); - task_wait_event(-1); -} |