From efd984ef633ae6aff597b300d917f93dd91160e1 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sun, 28 Jun 2020 08:24:49 -0700 Subject: [PATCH] Parse and add setup_hook and fields This change allows updates to the dev structure for individual test cases. This defines the "setup_hook" array, and "fields" map, at both the test group level and at the individual test case level, with the ones at the test case level overriding any parent level fields and/or hooks. The primary use case for this is to add new test definitions that would not be setup correctly by the default infrastructure, such as testing the LED function for the non-Pro X52, or setting up clock tests for local timezone, etc. --- lib/libx52/x52_test_gen.py | 18 +++++++++++++++++- lib/libx52/x52_tests.json | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/libx52/x52_test_gen.py b/lib/libx52/x52_test_gen.py index fa8cee6..6f7a85b 100755 --- a/lib/libx52/x52_test_gen.py +++ b/lib/libx52/x52_test_gen.py @@ -16,6 +16,7 @@ _TEST_FILE_HEADER = """/* #include #include #include +#include #include "x52_common.h" @@ -116,6 +117,10 @@ class Test(): self.name = group.name self.params_prefix = group.params_prefix self.params = obj["params"] + self.setup_hook = group.setup_hook + obj.get("setup_hook", []) + self.fields = group.fields.copy() + self.fields.update(obj.get("fields", {})) + if len(self.params_prefix) < len(self.params): self.params_prefix.extend([''] * (len(self.params) - len(self.params_prefix))) @@ -129,6 +134,16 @@ class Test(): def print(self): print(_TEST_FUNCTION_HEADER.format(self.definition())) + if self.fields: + for arg, val in self.fields.items(): + print(" dev->{} = {};".format(arg, val)) + + if self.setup_hook: + # Setup hook is an array of C commands that need to be executed + # prior to setting up the wrapper and running the tests + for hook in self.setup_hook: + print(" {}".format(hook)) + if self.output: print(" expect_function_calls(__wrap_libusb_control_transfer, {});".format(len(self.output))) print(" will_return_count(__wrap_libusb_control_transfer, LIBUSB_SUCCESS, {});".format(len(self.output))) @@ -157,7 +172,8 @@ class TestGroup(): """Load test cases from an object""" self.name = name self.function = obj["function"] - self.setup_hook = obj.get("setup_hook") + self.fields = obj.get("fields", {}) + self.setup_hook = obj.get("setup_hook", []) self.params_prefix = obj.get("params_prefix", []) self.tests = [] for test in obj["tests"]: diff --git a/lib/libx52/x52_tests.json b/lib/libx52/x52_tests.json index 77524e8..466f9ba 100644 --- a/lib/libx52/x52_tests.json +++ b/lib/libx52/x52_tests.json @@ -225,6 +225,23 @@ } ] }, + "LED_nonPro": { + "_comment": [ + "This suite checks if the LED state function returns not supported", + "when the device is an X52 (non-Pro) model" + ], + "function": "libx52_set_led_state", + "fields": { + "flags": "0" + }, + "params_prefix": ["LIBX52_LED_", "LIBX52_LED_STATE_"], + "tests": [ + { + "params": ["FIRE", "OFF"], + "retval": "NOT_SUPPORTED" + } + ] + }, "MFD": { "function": "libx52_set_text", "tests": [