Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Petri Latvala <petri.latvala@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t 5/7] lib/tests: Add unit tests for socket communication packet creation
Date: Fri, 28 Oct 2022 15:51:24 +0200	[thread overview]
Message-ID: <Y1veXEBaGuKimUlV@kamilkon-desk1> (raw)
In-Reply-To: <20221010145708.1986912-5-petri.latvala@intel.com>

Hi Petri,

imho a comment here would be nice, your choice.

Acked-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

On 2022-10-10 at 17:57:06 +0300, Petri Latvala wrote:
> Signed-off-by: Petri Latvala <petri.latvala@intel.com>
> Cc: Arkadiusz Hiler <arek@hiler.eu>
> ---
>  lib/tests/igt_runnercomms_packets.c | 263 ++++++++++++++++++++++++++++
>  lib/tests/meson.build               |   1 +
>  2 files changed, 264 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..167ad8e6
> --- /dev/null
> +++ b/lib/tests/igt_runnercomms_packets.c
> @@ -0,0 +1,263 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2022 Intel Corporation
> + */
> +
> +#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);
> +}
> +
> +
> +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)
> +{
> +	return runnerpacket_log(num8, text1);
> +}
> +
> +static void validate_log(struct runnerpacket *packet)
> +{
> +	runnerpacket_read_helper helper;
> +
> +	helper = read_runnerpacket(packet);
> +
> +	igt_assert_eq(packet->type, PACKETTYPE_LOG);
> +	igt_assert_eq(helper.type, PACKETTYPE_LOG);
> +
> +	igt_assert_eq(helper.log.stream, num8);
> +	igt_assert_eqstr(helper.log.text, text1);
> +}
> +
> +static struct runnerpacket *create_exec(void)
> +{
> +	char *argv[] = { strdup(text1), strdup(text2), strdup(text3), strdup(text4), NULL };
> +	struct runnerpacket *packet;
> +
> +	packet = runnerpacket_exec(argv);
> +
> +	free(argv[0]);
> +	free(argv[1]);
> +	free(argv[2]);
> +	free(argv[3]);
> +
> +	return packet;
> +}
> +
> +static void validate_exec(struct runnerpacket *packet)
> +{
> +	runnerpacket_read_helper helper;
> +	char cmpstr[256];
> +
> +	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)
> +{
> +	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)
> +{
> +	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)
> +{
> +	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)
> +{
> +	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)
> +{
> +	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)
> +{
> +	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)
> +{
> +	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") {
> +		struct runnerpacket *packet;
> +		runnerpacket_read_helper helper;
> +
> +		packet = runnerpacket_log(1, "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;
> +		runnerpacket_read_helper helper;
> +
> +		uint8_t num = 1;
> +		const char *text = "This is text";
> +		packet = runnerpacket_log(num, 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 d5666c24..7a52a787 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.30.2
> 

  reply	other threads:[~2022-10-28 13:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 14:57 [igt-dev] [PATCH i-g-t 1/7] lib/runnercomms: Structured communication from tests to igt_runner Petri Latvala
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 2/7] lib/igt_core: Send logs to runner with comms Petri Latvala
2022-10-28 13:46   ` Kamil Konieczny
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 3/7] runner: Use socket communications Petri Latvala
2022-10-28 13:47   ` Kamil Konieczny
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 4/7] runner/runner_tests: Add tests for " Petri Latvala
2022-10-28 13:49   ` Kamil Konieczny
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 5/7] lib/tests: Add unit tests for socket communication packet creation Petri Latvala
2022-10-28 13:51   ` Kamil Konieczny [this message]
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 6/7] runner: Add a socket comms decoder Petri Latvala
2022-10-28 13:52   ` Kamil Konieczny
2022-10-10 14:57 ` [igt-dev] [PATCH i-g-t 7/7] runner: Disable socket communications for now Petri Latvala
2022-10-28 13:59   ` Kamil Konieczny
2022-10-31 10:16     ` Petri Latvala
2022-10-10 15:56 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/7] lib/runnercomms: Structured communication from tests to igt_runner Patchwork
2022-10-10 21:05 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2022-10-11  6:25   ` Petri Latvala
2022-10-11 16:44     ` Vudum, Lakshminarayana
2022-10-11  6:45 ` Patchwork
2022-10-11 15:56 ` Patchwork
2022-10-11 16:38 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
2022-10-28 13:42 ` [igt-dev] [PATCH i-g-t 1/7] " Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1veXEBaGuKimUlV@kamilkon-desk1 \
    --to=kamil.konieczny@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox