Re: keep on patchin'

Craig Small <[email protected]> Tue, 25 Aug 2020 18:17:16 +1000
Newsgroups gmane.linux.procps.devel
Message-ID <CALy8Cw7MarPvy8ajjVJ8Utica28ptESSWKMQADJt7R0h0+H1hg@mail.gmail.com>
Hi Jim,
  I missed that patch at first, I thought you were just explaining
what happened.

I have tried to get the build system to work the way I want it but
there doesn't seem to be a neat way. The issue is you cannot even have
.o files in proc/ lying around otherwise it will link to those.  The
concept is to have a new library when you run make check that has
compiled .o files that have the define enabled and NOT have this
otherwise

I have seen where you can set a configure flag but to me, that means
it gets forgotten.

The suggestion I have come up with is a little, well, odd.  The test
program directly imports the .c file for the item it is testing.
Before it does that, it sets the required define so we get the debug
items.  I had toyed with the idea of moving some of those items into
the test program itself but was worried there were internal
dependencies so left them out for now.

It actually works, I switched two items around and did make test and:
proc/diskstats.c: enum/table error: Item_table[24] was
DISKSTATS_DELTA_WRITE_TIME, but its value is 25
proc/diskstats.c: enum/table error: Item_table[25] was
DISKSTATS_DELTA_IO_TIME, but its value is 24
FAIL proc/test_diskstats (exit status: 1)

Despite being very ugly, it does mean every make check checks for this
sort of thing which is a bonus. And because the definition happens in
a test programs .c file, it doesn't accidently get set for the "real"
library.

I have included one example. Let me know what you think

 - Craig

On Sun, 23 Aug 2020 at 17:48, Jim Warner <[email protected]> wrote:
>
> On Aug 19, 2020, at 3:33 PM, Jim Warner <[email protected]> wrote:
> > If the attached patch had been in place originally, I would have suffered an abend too.
> >
> > Thanks in advance for the push.
>
> ping
>
0001-build-sys-experimental-test-for-library.patch (text/x-patch, 2.2 KB)
From de1c9b90e2f0e46360906610fc7d8d512eaa544d Mon Sep 17 00:00:00 2001
From: Craig Small <[email protected]>
Date: Tue, 25 Aug 2020 18:06:49 +1000
Subject: [PATCH] build-sys: experimental test for library

Instead of trying to force the library to give up its secrets,
directly import the files for our test program.
---
 Makefile.am           |  3 +++
 proc/.gitignore       |  1 +
 proc/test_diskstats.c | 26 ++++++++++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100644 proc/test_diskstats.c

diff --git a/Makefile.am b/Makefile.am
index f3aac7ef..07c586c7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -329,6 +329,7 @@ lib_test_strtod_nol_LDADD = $(CYGWINFLAGS)
 
 noinst_PROGRAMS += \
 	proc/test_Itemtables \
+	proc/test_diskstats \
 	proc/test_pids \
 	proc/test_uptime \
 	proc/test_sysinfo \
@@ -337,6 +338,7 @@ noinst_PROGRAMS += \
 
 proc_test_Itemtables_SOURCES = proc/test_Itemtables.c
 proc_test_Itemtables_LDADD = proc/libprocps.la
+proc_test_diskstats_SOURCES = proc/test_diskstats.c
 proc_test_pids_SOURCES = proc/test_pids.c
 proc_test_pids_LDADD = proc/libprocps.la
 proc_test_uptime_SOURCES = proc/test_uptime.c
@@ -374,6 +376,7 @@ BUILT_SOURCES = $(top_srcdir)/.version
 # Test programs not used by dejagnu but run directly
 TESTS = \
 	proc/test_Itemtables \
+	proc/test_diskstats \
 	proc/test_pids \
 	proc/test_uptime \
 	proc/test_sysinfo \
diff --git a/proc/.gitignore b/proc/.gitignore
index a1db999a..4bfd47a2 100644
--- a/proc/.gitignore
+++ b/proc/.gitignore
@@ -1,4 +1,5 @@
 test_Itemtables
+test_diskstats
 test_namespace
 test_pids
 test_sysinfo
diff --git a/proc/test_diskstats.c b/proc/test_diskstats.c
new file mode 100644
index 00000000..75d71624
--- /dev/null
+++ b/proc/test_diskstats.c
@@ -0,0 +1,26 @@
+
+#include <stdlib.h>
+
+#include <proc/diskstats.h>
+
+#include "tests.h"
+
+#define ITEMTABLE_DEBUG
+#include "diskstats.c"
+
+static int check_diskstats (void *data) {
+    struct diskstats_info *ctx = NULL;
+    testname = "Itemtable check, diskstats";
+    if (0 == procps_diskstats_new(&ctx))
+        procps_diskstats_unref(&ctx);
+    return 1;
+}
+
+static TestFunction test_funcs[] = {
+    check_diskstats,
+    NULL
+};
+
+int main (void) {
+    return run_tests(test_funcs, NULL);
+}
-- 
2.26.0.rc2