From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 120F4C5B549 for ; Mon, 2 Jun 2025 06:27:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uLydI-00038Q-E0; Mon, 02 Jun 2025 02:26:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLyLV-0006do-HG for qemu-devel@nongnu.org; Mon, 02 Jun 2025 02:08:54 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLyLP-00026i-MF for qemu-devel@nongnu.org; Mon, 02 Jun 2025 02:08:25 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7406c6dd2b1so3959301b3a.0 for ; Sun, 01 Jun 2025 23:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748844502; x=1749449302; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e+c7qIyD0oro3iecT7W4w3fMH6+1rTgL3tcUjElcxFI=; b=EgUNIHwRRwB/VwuFsDJSwNYTkjl1PprNoCjjEHTYZLCFmefXd4I3Q4j9o80zPrQsw6 MJYDE6sA05G5UtKbMoV//hZZxrSe+KScGTP1VZ7Sl1vzQAa9wcyckwKgqXomEqBo58/d 7T+jMO3uSHo2AWCOv93nbJM4o3pgTvmtwOEXexG8VV8dq6t2UcxQudipiDj4eAPthFBg q+6MW8N6y0fyl1SV64Aq7GjMpNOwqNBxu6YQteCYZgjK6us/oIxpOCuPKw6RALRe8eCa Y/rzhQfztnHG0nrNeEDok2mtzS4vxRiwGxgrOj1VF4QFKEC+BF0L4JB472WZl++xQRcf ri/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748844502; x=1749449302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e+c7qIyD0oro3iecT7W4w3fMH6+1rTgL3tcUjElcxFI=; b=g2vrdtP6oE7UZSg4+3K1JEqBgTjDCo1zECXEhj2qjxKFarBvieHcgIvBwYPDLHHxxa aXx0EutmR0lzHiFEaCQyTatTDi6aQYbM3e4eK2rpqoCKiGUS+uLpHws0Y4f62hqiIYSw Fx0Nb5gzlyackJdmDWYMWSuO+8tlAXg296ZQtXIoFCcT0nJnYhxE1qeaq8QsmvvMShS4 Uc85XoI8Pffo4r07VBCQRMCUk+plcHzbQs4p6AkMVD2k3XUry15nktgSNmUbTsMwBLYu AUuu5ZtPgxWDeSDVj+uz9pnGgBFWvd+poHu8HiO43JJ6Rz40UyQ3km+9T/L1W26BkEoO 1+dg== X-Gm-Message-State: AOJu0YyQjU+1KXlUVqnWaFbdCYHv5EFPRWIyxakPfx20uq29zegBJyFR p88M1LHQipzEFwrZHiFM8LUWwD4DwgnnnT8hmpECu18liCTa0ojeGryjE+e7KOUudbw= X-Gm-Gg: ASbGncu2Xir3fPEk31jXBZ2L4MNd8KxPMoiA62AFTvmGJCj882Dj5yq2nPikNZ1IL1V wCUUIcEkC1t+3QdXEr6aqzVuP8tMkc08XN67A/nA5kkaiQS9tkKcDZbEU/MZGlwVZV4lhRwUZ78 ezJP1FM2ZS/FtsqNX6fmBX5nuO2mHYCrgJArDLTSVdDiFYU7jp6SFJO/Gq5EgvqbTOWo3K4CrXn hHVbPPcF/ip8OKNwp73DPIcWseVYsS8FFB5XncpAcWHkDqezhOEJfazdsce9rKxrPDM9ItuF55E 0tf+aOVQ1ianGAM66/U/Gwske7uHCqLBzULOvt8I5ZQaX9h4YGw= X-Google-Smtp-Source: AGHT+IH5SiFvJwejGiqxvS+fd32GDSVkgWEywtpJl9PGSw/O9qUbvNCKqNJGGsQP4dsdmW6vMdTgzQ== X-Received: by 2002:a05:6a21:164a:b0:1f3:1ba1:266a with SMTP id adf61e73a8af0-21adadc5d04mr17548123637.0.1748844501879; Sun, 01 Jun 2025 23:08:21 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-747afff7388sm7036966b3a.171.2025.06.01.23.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jun 2025 23:08:21 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Yanan Wang , Richard Henderson , Alexandre Iooss , Zhao Liu , Eduardo Habkost , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Marcel Apfelbaum , novafacing Subject: [PATCH v6 6/9] plugins: Add patcher plugin and test Date: Sun, 1 Jun 2025 23:08:12 -0700 Message-ID: <20250602060815.328261-7-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602060815.328261-1-rowanbhart@gmail.com> References: <20250602060815.328261-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: novafacing This patch adds a plugin that exercises the virtual and hardware memory read-write API functions added in a previous patch. The plugin takes a target and patch byte sequence, and will overwrite any instruction matching the target byte sequence with the patch. Signed-off-by: novafacing Signed-off-by: Rowan Hart --- tests/tcg/Makefile.target | 1 + tests/tcg/plugins/meson.build | 2 +- tests/tcg/plugins/patch.c | 297 ++++++++++++++++++++++ tests/tcg/x86_64/Makefile.softmmu-target | 32 ++- tests/tcg/x86_64/system/patch-target.c | 27 ++ tests/tcg/x86_64/system/validate-patch.py | 39 +++ 6 files changed, 392 insertions(+), 6 deletions(-) create mode 100644 tests/tcg/plugins/patch.c create mode 100644 tests/tcg/x86_64/system/patch-target.c create mode 100755 tests/tcg/x86_64/system/validate-patch.py diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 95ff76ea44..4b709a9d18 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -176,6 +176,7 @@ RUN_TESTS+=$(EXTRA_RUNS) # Some plugins need additional arguments above the default to fully # exercise things. We can define them on a per-test basis here. run-plugin-%-with-libmem.so: PLUGIN_ARGS=$(COMMA)inline=true +run-plugin-%-with-libpatch.so: PLUGIN_ARGS=$(COMMA)target=ffffffff$(COMMA)patch=00000000 ifeq ($(filter %-softmmu, $(TARGET)),) run-%: % diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build index 41f02f2c7f..163042e601 100644 --- a/tests/tcg/plugins/meson.build +++ b/tests/tcg/plugins/meson.build @@ -1,6 +1,6 @@ t = [] if get_option('plugins') - foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'reset', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'reset', 'syscall', 'patch'] if host_os == 'windows' t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c', include_directories: '../../../include/qemu', diff --git a/tests/tcg/plugins/patch.c b/tests/tcg/plugins/patch.c new file mode 100644 index 0000000000..6e83418b85 --- /dev/null +++ b/tests/tcg/plugins/patch.c @@ -0,0 +1,297 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This plugin patches instructions matching a pattern to a different + * instruction as they execute + * + */ + +#include "glib.h" +#include "glibconfig.h" + +#include +#include +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +static bool use_hwaddr; +static bool debug_insns; +static GByteArray *target_data; +static GByteArray *patch_data; + +/** + * Parse a string of hexadecimal digits into a GByteArray. The string must be + * even length + */ +static GByteArray *str_to_bytes(const char *str) +{ + GByteArray *bytes = g_byte_array_new(); + char byte[3] = {0}; + size_t len = strlen(str); + guint8 value = 0; + + if (len % 2 != 0) { + g_byte_array_free(bytes, true); + return NULL; + } + + for (size_t i = 0; i < len; i += 2) { + byte[0] = str[i]; + byte[1] = str[i + 1]; + value = (guint8)g_ascii_strtoull(byte, NULL, 16); + g_byte_array_append(bytes, &value, 1); + } + + return bytes; +} + +static void patch_hwaddr(unsigned int vcpu_index, void *userdata) +{ + uint64_t addr = (uint64_t)userdata; + GString *str = g_string_new(NULL); + g_string_printf(str, "patching: @0x%" + PRIx64 "\n", + addr); + qemu_plugin_outs(str->str); + g_string_free(str, true); + + enum qemu_plugin_hwaddr_operation_result result = + qemu_plugin_write_memory_hwaddr(addr, patch_data); + + + if (result != QEMU_PLUGIN_HWADDR_OPERATION_OK) { + GString *errmsg = g_string_new(NULL); + g_string_printf(errmsg, "Failed to write memory: %d\n", result); + qemu_plugin_outs(errmsg->str); + g_string_free(errmsg, true); + return; + } + + GByteArray *read_data = g_byte_array_new(); + + result = qemu_plugin_read_memory_hwaddr(addr, read_data, + patch_data->len); + + qemu_plugin_outs("Reading memory...\n"); + + if (result != QEMU_PLUGIN_HWADDR_OPERATION_OK) { + GString *errmsg = g_string_new(NULL); + g_string_printf(errmsg, "Failed to read memory: %d\n", result); + qemu_plugin_outs(errmsg->str); + g_string_free(errmsg, true); + return; + } + + if (memcmp(patch_data->data, read_data->data, patch_data->len) != 0) { + qemu_plugin_outs("Failed to read back written data\n"); + } + + qemu_plugin_outs("Success!\n"); + + return; +} + +static void patch_vaddr(unsigned int vcpu_index, void *userdata) +{ + uint64_t addr = (uint64_t)userdata; + uint64_t hwaddr = 0; + if (!qemu_plugin_translate_vaddr(addr, &hwaddr)) { + qemu_plugin_outs("Failed to translate vaddr\n"); + return; + } + GString *str = g_string_new(NULL); + g_string_printf(str, "patching: @0x%" + PRIx64 " hw: @0x%" PRIx64 "\n", + addr, hwaddr); + qemu_plugin_outs(str->str); + g_string_free(str, true); + + qemu_plugin_outs("Writing memory (vaddr)...\n"); + + if (!qemu_plugin_write_memory_vaddr(addr, patch_data)) { + qemu_plugin_outs("Failed to write memory\n"); + return; + } + + qemu_plugin_outs("Reading memory (vaddr)...\n"); + + + GByteArray *read_data = g_byte_array_new(); + + if (!qemu_plugin_read_memory_vaddr(addr, read_data, patch_data->len)) { + qemu_plugin_outs("Failed to read memory\n"); + return; + } + + if (memcmp(patch_data->data, read_data->data, patch_data->len) != 0) { + qemu_plugin_outs("Failed to read back written data\n"); + } + + qemu_plugin_outs("Success!\n"); + + return; +} + +static void debug_disas(unsigned int vcpu_index, void *userdata) +{ + GString *debug_info = (GString *)userdata; + qemu_plugin_outs(debug_info->str); +} + +static void debug_print_newline(unsigned int vcpu_index, void *userdata) +{ + qemu_plugin_outs("\n"); +} + +/* + * Callback on translation of a translation block. + */ +static void vcpu_tb_trans_cb(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + uint64_t addr = 0; + GByteArray *insn_data = g_byte_array_new(); + for (size_t i = 0; i < qemu_plugin_tb_n_insns(tb); i++) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + + if (use_hwaddr) { + uint64_t vaddr = qemu_plugin_insn_vaddr(insn); + if (!qemu_plugin_translate_vaddr(vaddr, &addr)) { + qemu_plugin_outs("Failed to translate vaddr\n"); + continue; + } + } else { + addr = qemu_plugin_insn_vaddr(insn); + } + + g_byte_array_set_size(insn_data, qemu_plugin_insn_size(insn)); + qemu_plugin_insn_data(insn, insn_data->data, insn_data->len); + + if (insn_data->len >= target_data->len && + !memcmp(insn_data->data, target_data->data, + MIN(target_data->len, insn_data->len))) { + if (use_hwaddr) { + qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_hwaddr, + QEMU_PLUGIN_CB_NO_REGS, + (void *)addr); + } else { + qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_vaddr, + QEMU_PLUGIN_CB_NO_REGS, + (void *)addr); + } + } + } + for (size_t i = 0; i < qemu_plugin_tb_n_insns(tb); i++) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + uint64_t vaddr = qemu_plugin_insn_vaddr(insn); + uint64_t hwaddr = (uint64_t)qemu_plugin_insn_haddr(insn); + uint64_t translated_hwaddr = 0; + if (!qemu_plugin_translate_vaddr(vaddr, &translated_hwaddr)) { + qemu_plugin_outs("Failed to translate vaddr\n"); + continue; + } + char *disas = qemu_plugin_insn_disas(insn); + GString *str = g_string_new(NULL); + g_string_printf(str, + "vaddr: 0x%" PRIx64 " hwaddr: 0x%" PRIx64 + " translated: 0x%" PRIx64 " : %s\n", + vaddr, hwaddr, translated_hwaddr, disas); + g_free(disas); + if (debug_insns) { + qemu_plugin_register_vcpu_insn_exec_cb(insn, debug_disas, + QEMU_PLUGIN_CB_NO_REGS, + str); + } + + } + + if (debug_insns) { + qemu_plugin_register_vcpu_tb_exec_cb(tb, debug_print_newline, + QEMU_PLUGIN_CB_NO_REGS, + NULL); + } + + g_byte_array_free(insn_data, true); +} + +static void usage(void) +{ + fprintf(stderr, "Usage: ,target=,patch=" + "[,use_hwaddr=]" + "[,debug_insns=]\n"); +} + +/* + * Called when the plugin is installed + */ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int argc, + char **argv) +{ + + use_hwaddr = true; + debug_insns = false; + target_data = NULL; + patch_data = NULL; + + if (argc > 4) { + usage(); + return -1; + } + + for (size_t i = 0; i < argc; i++) { + char *opt = argv[i]; + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); + if (g_strcmp0(tokens[0], "use_hwaddr") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &use_hwaddr)) { + fprintf(stderr, + "Failed to parse boolean argument use_hwaddr\n"); + return -1; + } + } else if (g_strcmp0(tokens[0], "debug_insns") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &debug_insns)) { + fprintf(stderr, + "Failed to parse boolean argument debug_insns\n"); + return -1; + } + } else if (g_strcmp0(tokens[0], "target") == 0) { + target_data = str_to_bytes(tokens[1]); + if (!target_data) { + fprintf(stderr, + "Failed to parse target bytes.\n"); + return -1; + } + } else if (g_strcmp0(tokens[0], "patch") == 0) { + patch_data = str_to_bytes(tokens[1]); + if (!patch_data) { + fprintf(stderr, "Failed to parse patch bytes.\n"); + return -1; + } + } else { + fprintf(stderr, "Unknown argument: %s\n", tokens[0]); + usage(); + return -1; + } + } + + if (!target_data) { + fprintf(stderr, "target argument is required\n"); + usage(); + return -1; + } + + if (!patch_data) { + fprintf(stderr, "patch argument is required\n"); + usage(); + return -1; + } + + if (target_data->len != patch_data->len) { + fprintf(stderr, "Target and patch data must be the same length\n"); + return -1; + } + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans_cb); + + return 0; +} diff --git a/tests/tcg/x86_64/Makefile.softmmu-target b/tests/tcg/x86_64/Makefile.softmmu-target index ef6bcb4dc7..8d3a067c33 100644 --- a/tests/tcg/x86_64/Makefile.softmmu-target +++ b/tests/tcg/x86_64/Makefile.softmmu-target @@ -7,18 +7,27 @@ # I386_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/i386/system -X64_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/x86_64/system +X86_64_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/x86_64/system # These objects provide the basic boot code and helper functions for all tests CRT_OBJS=boot.o -CRT_PATH=$(X64_SYSTEM_SRC) -LINK_SCRIPT=$(X64_SYSTEM_SRC)/kernel.ld +X86_64_TEST_C_SRCS=$(wildcard $(X86_64_SYSTEM_SRC)/*.c) +X86_64_TEST_S_SRCS= + +X86_64_C_TESTS = $(patsubst $(X86_64_SYSTEM_SRC)/%.c, %, $(X86_64_TEST_C_SRCS)) +X86_64_S_TESTS = $(patsubst $(X86_64_SYSTEM_SRC)/%.S, %, $(X86_64_TEST_S_SRCS)) + +X86_64_TESTS = $(X86_64_C_TESTS) +X86_64_TESTS += $(X86_64_S_TESTS) + +CRT_PATH=$(X86_64_SYSTEM_SRC) +LINK_SCRIPT=$(X86_64_SYSTEM_SRC)/kernel.ld LDFLAGS=-Wl,-T$(LINK_SCRIPT) -Wl,-melf_x86_64 CFLAGS+=-nostdlib -ggdb -O0 $(MINILIB_INC) LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc -TESTS+=$(MULTIARCH_TESTS) +TESTS+=$(X86_64_TESTS) $(MULTIARCH_TESTS) EXTRA_RUNS+=$(MULTIARCH_RUNS) # building head blobs @@ -27,11 +36,24 @@ EXTRA_RUNS+=$(MULTIARCH_RUNS) %.o: $(CRT_PATH)/%.S $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wa,--noexecstack -c $< -o $@ -# Build and link the tests +# Build and link the multiarch tests %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) +# Build and link the arch tests +%: $(X86_64_SYSTEM_SRC)/%.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + memory: CFLAGS+=-DCHECK_UNALIGNED=1 +patch-target: CFLAGS+=-O0 # Running QEMU_OPTS+=-device isa-debugcon,chardev=output -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel + +# Add patch-target to ADDITIONAL_PLUGINS_TESTS +ADDITIONAL_PLUGINS_TESTS += patch-target + +run-plugin-patch-target-with-libpatch.so: \ + PLUGIN_ARGS=$(COMMA)target=ffc0$(COMMA)patch=9090$(COMMA)use_hwaddr=true$(COMMA)debug_insns=false +run-plugin-patch-target-with-libpatch.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=$(X86_64_SYSTEM_SRC)/validate-patch.py $@.out \ No newline at end of file diff --git a/tests/tcg/x86_64/system/patch-target.c b/tests/tcg/x86_64/system/patch-target.c new file mode 100644 index 0000000000..8a7c0a0ae8 --- /dev/null +++ b/tests/tcg/x86_64/system/patch-target.c @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This test target increments a value 100 times. The patcher converts the + * inc instruction to a nop, so it only increments the value once. + * + */ +#include + +int main(void) +{ + ml_printf("Running test...\n"); +#if defined(__x86_64__) + ml_printf("Testing insn memory read/write...\n"); + unsigned int x = 0; + for (int i = 0; i < 100; i++) { + asm volatile ( + "inc %[x]" + : [x] "+a" (x) + ); + } + ml_printf("Value: %d\n", x); +#else + #error "This test is only valid for x86_64 architecture." +#endif + return 0; +} diff --git a/tests/tcg/x86_64/system/validate-patch.py b/tests/tcg/x86_64/system/validate-patch.py new file mode 100755 index 0000000000..700950eae5 --- /dev/null +++ b/tests/tcg/x86_64/system/validate-patch.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# +# validate-patch.py: check the patch applies +# +# This program takes two inputs: +# - the plugin output +# - the binary output +# +# Copyright (C) 2024 +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import sys +from argparse import ArgumentParser + +def main() -> None: + """ + Process the arguments, injest the program and plugin out and + verify they match up and report if they do not. + """ + parser = ArgumentParser(description="Validate patch") + parser.add_argument('test_output', + help="The output from the test itself") + parser.add_argument('plugin_output', + help="The output from plugin") + args = parser.parse_args() + + with open(args.test_output, 'r') as f: + test_data = f.read() + with open(args.plugin_output, 'r') as f: + plugin_data = f.read() + if "Value: 1" in test_data: + sys.exit(0) + else: + sys.exit(1) + +if __name__ == "__main__": + main() + -- 2.49.0