[PATCH i-g-t 19/28] Unit test normal creation for all packet types
Petri Latvala
petri.latvala at intel.com
Mon Mar 22 11:34:11 UTC 2021
---
lib/tests/igt_runnercomms_packets.c | 232 ++++++++++++++++++++++++----
1 file changed, 198 insertions(+), 34 deletions(-)
diff --git a/lib/tests/igt_runnercomms_packets.c b/lib/tests/igt_runnercomms_packets.c
index 1550c485..79b9bb20 100644
--- a/lib/tests/igt_runnercomms_packets.c
+++ b/lib/tests/igt_runnercomms_packets.c
@@ -35,50 +35,214 @@ static void igt_assert_eqstr(const char *one, const char *two)
igt_assert_f(!strcmp(one, two), "Strings differ: '%s' vs '%s'\n", one, two);
}
-igt_main
+
+static const uint8_t num8 = 5;
+static const int32_t num32 = -67;
+static const char *text1 = "Text one";
+static const char *text2 = "Text two";
+static const char *text3 = "Text three";
+static const char *text4 = "Text four";
+
+static struct runnerpacket *create_log(void)
{
- igt_subtest("create-and-parse-normal-log") {
- /* LOG is a simple packet to parse */
- struct runnerpacket *packet;
- union runnerpacket_read_helper helper;
+ return runnerpacket_log(num8, text1);
+}
- uint8_t num = 1;
- const char *text = "This is a text";
+static void validate_log(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
- packet = runnerpacket_log(num, text);
- igt_assert(packet != NULL);
- igt_assert_eq(packet->type, PACKETTYPE_LOG);
- helper = read_runnerpacket(packet);
+ helper = read_runnerpacket(packet);
- igt_assert_eq(helper.type, PACKETTYPE_LOG);
- igt_assert_eq(helper.log.stream, num);
- igt_assert_eqstr(helper.log.text, text);
+ igt_assert_eq(packet->type, PACKETTYPE_LOG);
+ igt_assert_eq(helper.type, PACKETTYPE_LOG);
- free(packet);
- }
+ igt_assert_eq(helper.log.stream, num8);
+ igt_assert_eqstr(helper.log.text, text1);
+}
- igt_subtest("create-and-parse-normal-subtest-result") {
- /* SUBTEST_RESULT has multiple strings and nul-termination needs to be counted correctly in the size */
- struct runnerpacket *packet;
- union runnerpacket_read_helper helper;
+static struct runnerpacket *create_exec(void)
+{
+ char *argv[] = { strdup(text1), strdup(text2), strdup(text3), strdup(text4), NULL };
+ struct runnerpacket *packet;
- const char *text1 = "This is text one";
- const char *text2 = "This is text two";
- const char *text3 = "This is text three";
- const char *text4 = "This is text four";
+ packet = runnerpacket_exec(argv);
- packet = runnerpacket_subtest_result(text1, text2, text3, text4);
- igt_assert(packet != NULL);
- igt_assert_eq(packet->type, PACKETTYPE_SUBTEST_RESULT);
- helper = read_runnerpacket(packet);
+ free(argv[0]);
+ free(argv[1]);
+ free(argv[2]);
+ free(argv[3]);
+
+ return packet;
+}
- igt_assert_eq(helper.type, PACKETTYPE_SUBTEST_RESULT);
- igt_assert_eqstr(helper.subtestresult.name, text1);
- igt_assert_eqstr(helper.subtestresult.result, text2);
- igt_assert_eqstr(helper.subtestresult.timeused, text3);
- igt_assert_eqstr(helper.subtestresult.reason, text4);
+static void validate_exec(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+ char cmpstr[256];
- free(packet);
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_EXEC);
+ igt_assert_eq(helper.type, PACKETTYPE_EXEC);
+
+ snprintf(cmpstr, sizeof(cmpstr), "%s %s %s %s", text1, text2, text3, text4);
+ igt_assert_eqstr(helper.exec.cmdline, cmpstr);
+}
+
+static struct runnerpacket *create_exit(void)
+{
+ return runnerpacket_exit(num32, text1);
+}
+
+static void validate_exit(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_EXIT);
+ igt_assert_eq(helper.type, PACKETTYPE_EXIT);
+
+ igt_assert_eq(helper.exit.exitcode, num32);
+ igt_assert_eqstr(helper.exit.timeused, text1);
+}
+
+static struct runnerpacket *create_subtest_start(void)
+{
+ return runnerpacket_subtest_start(text1);
+}
+
+static void validate_subtest_start(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_SUBTEST_START);
+ igt_assert_eq(helper.type, PACKETTYPE_SUBTEST_START);
+
+ igt_assert_eqstr(helper.subteststart.name, text1);
+}
+
+static struct runnerpacket *create_subtest_result(void)
+{
+ return runnerpacket_subtest_result(text1, text2, text3, text4);
+}
+
+static void validate_subtest_result(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_SUBTEST_RESULT);
+ igt_assert_eq(helper.type, PACKETTYPE_SUBTEST_RESULT);
+
+ igt_assert_eqstr(helper.subtestresult.name, text1);
+ igt_assert_eqstr(helper.subtestresult.result, text2);
+ igt_assert_eqstr(helper.subtestresult.timeused, text3);
+ igt_assert_eqstr(helper.subtestresult.reason, text4);
+}
+
+static struct runnerpacket *create_dynamic_subtest_start(void)
+{
+ return runnerpacket_dynamic_subtest_start(text1);
+}
+
+static void validate_dynamic_subtest_start(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_DYNAMIC_SUBTEST_START);
+ igt_assert_eq(helper.type, PACKETTYPE_DYNAMIC_SUBTEST_START);
+
+ igt_assert_eqstr(helper.dynamicsubteststart.name, text1);
+}
+
+static struct runnerpacket *create_dynamic_subtest_result(void)
+{
+ return runnerpacket_dynamic_subtest_result(text1, text2, text3, text4);
+}
+
+static void validate_dynamic_subtest_result(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_DYNAMIC_SUBTEST_RESULT);
+ igt_assert_eq(helper.type, PACKETTYPE_DYNAMIC_SUBTEST_RESULT);
+
+ igt_assert_eqstr(helper.dynamicsubtestresult.name, text1);
+ igt_assert_eqstr(helper.dynamicsubtestresult.result, text2);
+ igt_assert_eqstr(helper.dynamicsubtestresult.timeused, text3);
+ igt_assert_eqstr(helper.dynamicsubtestresult.reason, text4);
+}
+
+static struct runnerpacket *create_versionstring(void)
+{
+ return runnerpacket_versionstring(text1);
+}
+
+static void validate_versionstring(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_VERSIONSTRING);
+ igt_assert_eq(helper.type, PACKETTYPE_VERSIONSTRING);
+
+ igt_assert_eqstr(helper.versionstring.text, text1);
+}
+
+static struct runnerpacket *create_result_override(void)
+{
+ return runnerpacket_resultoverride(text1);
+}
+
+static void validate_result_override(struct runnerpacket *packet)
+{
+ union runnerpacket_read_helper helper;
+
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(packet->type, PACKETTYPE_RESULT_OVERRIDE);
+ igt_assert_eq(helper.type, PACKETTYPE_RESULT_OVERRIDE);
+
+ igt_assert_eqstr(helper.resultoverride.result, text1);
+}
+
+struct {
+ struct runnerpacket * (*create)(void);
+ void (*validate)(struct runnerpacket *packet);
+} basic_creation[] = {
+ { create_log, validate_log },
+ { create_exec, validate_exec },
+ { create_exit, validate_exit },
+ { create_subtest_start, validate_subtest_start },
+ { create_subtest_result, validate_subtest_result },
+ { create_dynamic_subtest_start, validate_dynamic_subtest_start },
+ { create_dynamic_subtest_result, validate_dynamic_subtest_result },
+ { create_versionstring, validate_versionstring },
+ { create_result_override, validate_result_override },
+ { NULL, NULL }
+};
+
+igt_main
+{
+ igt_subtest("create-and-parse-normal") {
+ for (typeof (*basic_creation) *t = basic_creation; t->create; t++) {
+ struct runnerpacket *packet;
+
+ packet = t->create();
+ igt_assert(packet != NULL);
+ igt_assert(packet->type != PACKETTYPE_INVALID);
+ t->validate(packet);
+ }
}
igt_subtest("packet-too-short") {
--
2.29.2
More information about the Intel-gfx-trybot
mailing list