Skip to contentSkip to conversation

libtracefs: Use LIBTRACEFS_STATIC for utest

PATCH In review Benjamin Drung 2 participants 8 messages Jun 5 – Sep 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libtracefs: Use LIBTRACEFS_STATIC for utest

The top-level Makefile already sets LIBTRACEFS_STATIC. To allow overriding the static libtracefs library using just this variable, use LIBTRACEFS_STATIC in the utest Makefile as well.

---
 utest/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
utest/Makefile +4 -2
index f10b709..9bd3dea 100644
@@ -10,9 +10,11 @@ OBJS =
 OBJS += trace-utest.o
 OBJS += tracefs-utest.o
 
+LIBTRACEFS_STATIC ?= $(obj)/lib/libtracefs.a
+
 LIBS += -lcunit				\
 	-ldl				\
-	$(obj)/lib/libtracefs.a
+	$(LIBTRACEFS_STATIC)
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
@@ -21,7 +23,7 @@ $(bdir):
 
 $(OBJS): | $(bdir)
 
-$(bdir)/trace-utest: $(OBJS) $(obj)/lib/libtracefs.a
+$(bdir)/trace-utest: $(OBJS) $(LIBTRACEFS_STATIC)
 	$(Q)$(do_app_build)
 
 $(bdir)/%.o: %.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 libtracefs: Support EXTRA_LIBS for utest

Allow building the utest against the system installed libtracefs library by tweaking the make variables:

```
make LIBTRACEFS_STATIC= EXTRA_LIBS=-ltracefs test
```

Note: This still requires making tfs_find_debug_tracing_dir available.

---
 utest/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utest/Makefile +2 -1
index 9bd3dea..bcb87b6 100644
@@ -14,7 +14,8 @@ LIBTRACEFS_STATIC ?= $(obj)/lib/libtracefs.a
 
 LIBS += -lcunit				\
 	-ldl				\
-	$(LIBTRACEFS_STATIC)
+	$(LIBTRACEFS_STATIC)		\
+	$(EXTRA_LIBS)
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
Signature · 1 line
2.53.0
#2 lore raw
In reply to Benjamin Drung

Sorry for the late reply. I finally have time to look at these patches.

They look fine but both of them are missing your Signed-off-by. I can't take them without that.

Thanks,

-- Steve

Quoted 33 lines · On Fri, 05 Jun 2026 14:53:21 +0000 Benjamin Drung…

The top-level Makefile already sets LIBTRACEFS_STATIC. To allow overriding the static libtracefs library using just this variable, use LIBTRACEFS_STATIC in the utest Makefile as well.

---
 utest/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
utest/Makefile +4 -2
index f10b709..9bd3dea 100644
@@ -10,9 +10,11 @@ OBJS =
 OBJS += trace-utest.o
 OBJS += tracefs-utest.o
 
+LIBTRACEFS_STATIC ?= $(obj)/lib/libtracefs.a
+
 LIBS += -lcunit				\
 	-ldl				\
-	$(obj)/lib/libtracefs.a
+	$(LIBTRACEFS_STATIC)
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
@@ -21,7 +23,7 @@ $(bdir):
 
 $(OBJS): | $(bdir)
 
-$(bdir)/trace-utest: $(OBJS) $(obj)/lib/libtracefs.a
+$(bdir)/trace-utest: $(OBJS) $(LIBTRACEFS_STATIC)
 	$(Q)$(do_app_build)
 
 $(bdir)/%.o: %.c
#3 lore raw

v2 cover Ubuntu patches

Hi,

with quite some delay, here are the requested changes.

v2:
- Added missing Signed-off-by tags.

Adrien Nader (1):
libtracefs utest: Only use online CPUs during tests

Benjamin Drung (2):
libtracefs: Use LIBTRACEFS_STATIC for utest
libtracefs: Support EXTRA_LIBS for utest

 utest/Makefile        |  7 +++++--
 utest/tracefs-utest.c | 10 +++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)
Signature · 1 line
2.53.0
#4 lore raw

PATCH v2 1/3 libtracefs utest: Only use online CPUs during tests

From: Adrien Nader <[email protected]>

We cannot do operations over offline cores. Virtual machines can routinely announce the presence of all of the host's cores and only make some of them online.

This change assumes that all the online CPUs are continuously numbered and start at 0. While this is not perfect, it is still an improvement and might be enough, especially considering this touches tests only.

---
 utest/tracefs-utest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
utest/tracefs-utest.c +5 -5
index e3ff215..665c7d9 100644
@@ -181,7 +181,7 @@ static void save_affinity(void)
 {
 	int cpus;
 
-	cpus = sysconf(_SC_NPROCESSORS_CONF);
+	cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	cpuset_save = CPU_ALLOC(cpus);
 	cpuset = CPU_ALLOC(cpus);
 	cpu_size = CPU_ALLOC_SIZE(cpus);
@@ -216,7 +216,7 @@ static void test_iter_write(struct tracefs_instance *instance)
 	int cpus;
 	int ret;
 
-	cpus = sysconf(_SC_NPROCESSORS_CONF);
+	cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	save_affinity();
 
 	path = tracefs_instance_get_file(instance, "trace_marker");
@@ -243,7 +243,7 @@ static void test_iter_write(struct tracefs_instance *instance)
 
 static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu, bool snapshot)
 {
-	int cpus = sysconf(_SC_NPROCESSORS_CONF);
+	int cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	cpu_set_t *cpuset = NULL;
 	int cpu_size = 0;
 	int check = 0;
@@ -292,7 +292,7 @@ static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu, b
 
 static void test_instance_iter_raw_events(struct tracefs_instance *instance)
 {
-	int cpus = sysconf(_SC_NPROCESSORS_CONF);
+	int cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int ret;
 	int i;
 
@@ -317,7 +317,7 @@ static void test_iter_raw_events(void)
 
 static void test_instance_iter_snapshot_events(struct tracefs_instance *instance)
 {
-	int cpus = sysconf(_SC_NPROCESSORS_CONF);
+	int cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int i;
 
 	iter_raw_events_on_cpu(instance, -1, true);
Signature · 1 line
2.53.0
#5 lore raw

PATCH v2 2/3 libtracefs: Use LIBTRACEFS_STATIC for utest

In reply to Benjamin Drung

The top-level Makefile already sets LIBTRACEFS_STATIC. To allow overriding the static libtracefs library using just this variable, use LIBTRACEFS_STATIC in the utest Makefile as well.

---
 utest/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
utest/Makefile +4 -2
index f10b709..9bd3dea 100644
@@ -10,9 +10,11 @@ OBJS =
 OBJS += trace-utest.o
 OBJS += tracefs-utest.o
 
+LIBTRACEFS_STATIC ?= $(obj)/lib/libtracefs.a
+
 LIBS += -lcunit				\
 	-ldl				\
-	$(obj)/lib/libtracefs.a
+	$(LIBTRACEFS_STATIC)
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
@@ -21,7 +23,7 @@ $(bdir):
 
 $(OBJS): | $(bdir)
 
-$(bdir)/trace-utest: $(OBJS) $(obj)/lib/libtracefs.a
+$(bdir)/trace-utest: $(OBJS) $(LIBTRACEFS_STATIC)
 	$(Q)$(do_app_build)
 
 $(bdir)/%.o: %.c
Signature · 1 line
2.53.0
#6 lore raw

PATCH v2 3/3 libtracefs: Support EXTRA_LIBS for utest

In reply to Benjamin Drung

Allow building the utest against the system installed libtracefs library by tweaking the make variables:

```
make LIBTRACEFS_STATIC= EXTRA_LIBS=-ltracefs test
```

Note: This still requires making tfs_find_debug_tracing_dir available.

---
 utest/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
utest/Makefile +2 -1
index 9bd3dea..bcb87b6 100644
@@ -14,7 +14,8 @@ LIBTRACEFS_STATIC ?= $(obj)/lib/libtracefs.a
 
 LIBS += -lcunit				\
 	-ldl				\
-	$(LIBTRACEFS_STATIC)
+	$(LIBTRACEFS_STATIC)		\
+	$(EXTRA_LIBS)
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH v2 0/3] Ubuntu patches

In reply to Benjamin Drung

Thanks,

I'm actually in the middle of traveling until Oct 10th and will likely not be able to look at these until then.I'm hoping to triage the bugs and changes sent to the trace-cmd and library code in October.

-- Steve

Quoted 18 lines · On Wed, 23 Sep 2026 22:56:29 +0200 Benjamin Drung…

Hi,

with quite some delay, here are the requested changes.

v2:
- Added missing Signed-off-by tags.

Adrien Nader (1):
libtracefs utest: Only use online CPUs during tests

Benjamin Drung (2):
libtracefs: Use LIBTRACEFS_STATIC for utest
libtracefs: Support EXTRA_LIBS for utest

 utest/Makefile        |  7 +++++--
 utest/tracefs-utest.c | 10 +++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)