[PATCH i-g-t 02/16] comms unit test
Petri Latvala
petri.latvala at intel.com
Mon Mar 1 12:58:31 UTC 2021
---
lib/tests/igt_runnercomms_packets.c | 120 ++++++++++++++++++++++++++++
lib/tests/meson.build | 1 +
2 files changed, 121 insertions(+)
create mode 100644 lib/tests/igt_runnercomms_packets.c
diff --git a/lib/tests/igt_runnercomms_packets.c b/lib/tests/igt_runnercomms_packets.c
new file mode 100644
index 00000000..3ae21005
--- /dev/null
+++ b/lib/tests/igt_runnercomms_packets.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2021 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "runnercomms.h"
+
+#include "igt_core.h"
+
+static void igt_assert_eqstr(const char *one, const char *two)
+{
+ if (one == NULL && two == NULL)
+ return;
+
+ igt_assert_f(one != NULL && two != NULL, "Strings differ (one is NULL): %s vs %s\n", one, two);
+
+ igt_assert_f(!strcmp(one, two), "Strings differ: '%s' vs '%s'\n", one, two);
+}
+
+igt_main
+{
+ igt_subtest("create-and-parse-normal-log") {
+ /* LOG is a simple packet to parse */
+ struct runnerpacket *packet;
+ union runnerpacket_read_helper helper;
+
+ uint8_t num1 = 1;
+ uint8_t num2 = 2;
+ const char *text = "This is a text";
+
+ packet = runnerpacket_log(num1, num2, text);
+ igt_assert(packet != NULL);
+ igt_assert_eq(packet->type, PACKETTYPE_LOG);
+ helper = read_runnerpacket(packet);
+
+ igt_assert_eq(helper.type, PACKETTYPE_LOG);
+ igt_assert_eq(helper.log.stream, num1);
+ igt_assert_eq(helper.log.level, num2);
+ igt_assert_eqstr(helper.log.text, text);
+
+ free(packet);
+ }
+
+ 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;
+
+ 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_subtest_result(text1, text2, text3, text4);
+ igt_assert(packet != NULL);
+ igt_assert_eq(packet->type, PACKETTYPE_SUBTEST_RESULT);
+ helper = read_runnerpacket(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);
+
+ free(packet);
+ }
+
+ igt_subtest("packet-too-short") {
+ struct runnerpacket *packet;
+ union runnerpacket_read_helper helper;
+
+ packet = runnerpacket_log(1, 2, "Hello");
+ igt_assert(packet != NULL);
+ igt_assert_eq(packet->type, PACKETTYPE_LOG);
+
+ packet->size = 4; /* not even sizeof(*packet) */
+ helper = read_runnerpacket(packet);
+ igt_assert_eq(helper.type, PACKETTYPE_INVALID);
+
+ free(packet);
+ }
+
+ igt_subtest("nul-termination-missing") {
+ /* Parsing should reject the packet when nul-termination is missing */
+ struct runnerpacket *packet;
+ union runnerpacket_read_helper helper;
+
+ uint8_t num1 = 1;
+ uint8_t num2 = 2;
+ const char *text = "This is text";
+ packet = runnerpacket_log(num1, num2, text);
+ igt_assert(packet != NULL);
+ igt_assert_eq(packet->type, PACKETTYPE_LOG);
+
+ /* make the packet too short to include the nul-termination in the string */
+ packet->size -= 2;
+ helper = read_runnerpacket(packet);
+ igt_assert_eq(helper.type, PACKETTYPE_INVALID);
+
+ free(packet);
+ }
+}
diff --git a/lib/tests/meson.build b/lib/tests/meson.build
index 9cf5ff47..d44b7a1c 100644
--- a/lib/tests/meson.build
+++ b/lib/tests/meson.build
@@ -14,6 +14,7 @@ lib_tests = [
'igt_invalid_subtest_name',
'igt_nesting',
'igt_no_exit',
+ 'igt_runnercomms_packets',
'igt_segfault',
'igt_simulation',
'igt_stats',
--
2.29.2
More information about the Intel-gfx-trybot
mailing list