mirror of https://github.com/nirenjan/libx52.git
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.pull/22/head
parent
108b7e2522
commit
efd984ef63
|
@ -16,6 +16,7 @@ _TEST_FILE_HEADER = """/*
|
|||
#include <cmocka.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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"]:
|
||||
|
|
|
@ -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": [
|
||||
|
|
Loading…
Reference in New Issue