* [PATCH 0/3] Fix unit tests and APIs for loading saved mappings
@ 2021-04-12 4:24 Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 1/3] libtracefs: Fix trace options unit test Tzvetomir Stoyanov (VMware)
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-04-12 4:24 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel
Some last minute changes broke the unit tests of the library. While running
the tests, noticed also the problem in the logic that loads saved command
lines, kallsyms and printk formats.
Tzvetomir Stoyanov (VMware) (3):
libtracefs: Fix trace options unit test
libtracefs: Fix loading of saved maps
libtracefs: Fixed trace marker unit test
src/tracefs-events.c | 6 +++---
utest/tracefs-utest.c | 25 +++++--------------------
2 files changed, 8 insertions(+), 23 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] libtracefs: Fix trace options unit test
2021-04-12 4:24 [PATCH 0/3] Fix unit tests and APIs for loading saved mappings Tzvetomir Stoyanov (VMware)
@ 2021-04-12 4:24 ` Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 2/3] libtracefs: Fix loading of saved maps Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 3/3] libtracefs: Fixed trace marker unit test Tzvetomir Stoyanov (VMware)
2 siblings, 0 replies; 4+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-04-12 4:24 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel
Changes to tracefs library APIs were introduced by this patch set:
https://lore.kernel.org/linux-trace-devel/20210409180423.72497-1-y.karadz@gmail.com/
which make the option mask immutable and controlled by the library.
However, the unit test was not updated and fails.
Fixed the trace options unit test, to reflect the changes in the API.
Reported-by: Sameeruddin Shaik <sameeruddin.shaik8@gmail.com>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
utest/tracefs-utest.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 1f48e6f..04b5e81 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -679,21 +679,11 @@ out:
return ret;
}
-static bool check_options_mask_empty(struct tracefs_options_mask *mask)
-{
- int i;
-
- for (i = 1; i < TRACEFS_OPTION_MAX; i++) {
- if (tracefs_option_mask_is_set(mask, i))
- return false;
- }
- return true;
-}
-
static void test_instance_tracing_options(struct tracefs_instance *instance)
{
- struct tracefs_options_mask *enabled;
- struct tracefs_options_mask *all, *all_copy;
+ const struct tracefs_options_mask *enabled;
+ const struct tracefs_options_mask *all_copy;
+ const struct tracefs_options_mask *all;
enum tracefs_option_id i = 1;
char file[PATH_MAX];
const char *name;
@@ -743,11 +733,6 @@ static void test_instance_tracing_options(struct tracefs_instance *instance)
CU_TEST(check_option(instance, i, true, 0));
}
}
- CU_TEST(check_options_mask_empty(all));
- CU_TEST(check_options_mask_empty(enabled));
-
- free(all);
- free(enabled);
}
static void test_tracing_options(void)
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] libtracefs: Fix loading of saved maps
2021-04-12 4:24 [PATCH 0/3] Fix unit tests and APIs for loading saved mappings Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 1/3] libtracefs: Fix trace options unit test Tzvetomir Stoyanov (VMware)
@ 2021-04-12 4:24 ` Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 3/3] libtracefs: Fixed trace marker unit test Tzvetomir Stoyanov (VMware)
2 siblings, 0 replies; 4+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-04-12 4:24 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel
The internal helper function, used for loading saved printk formats,
kallsyms and command lines retuns 0 in case the given file exist,
but is empty. In that case a buffer is not allocated and size 0 is
returned. Logic for loading those mappings does not handle that case,
which leads to memory corrupion freeing invalid memory.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
src/tracefs-events.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 94573b3..3a6196b 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -603,7 +603,7 @@ static void load_kallsyms(struct tep_handle *tep)
{
char *buf;
- if (str_read_file("/proc/kallsyms", &buf, false) < 0)
+ if (str_read_file("/proc/kallsyms", &buf, false) <= 0)
return;
tep_parse_kallsyms(tep, buf);
@@ -623,7 +623,7 @@ static int load_saved_cmdlines(const char *tracing_dir,
ret = str_read_file(path, &buf, false);
free(path);
- if (ret < 0)
+ if (ret <= 0)
return -1;
ret = tep_parse_saved_cmdlines(tep, buf);
@@ -645,7 +645,7 @@ static void load_printk_formats(const char *tracing_dir,
ret = str_read_file(path, &buf, false);
free(path);
- if (ret < 0)
+ if (ret <= 0)
return;
tep_parse_printk_formats(tep, buf);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] libtracefs: Fixed trace marker unit test
2021-04-12 4:24 [PATCH 0/3] Fix unit tests and APIs for loading saved mappings Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 1/3] libtracefs: Fix trace options unit test Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 2/3] libtracefs: Fix loading of saved maps Tzvetomir Stoyanov (VMware)
@ 2021-04-12 4:24 ` Tzvetomir Stoyanov (VMware)
2 siblings, 0 replies; 4+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-04-12 4:24 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel
The tracefs_printf() and tracefs_vprintf() APIs do not write the terminating
NULL characted of the string in the trace marker, as it is not required
by the kernel interafce. Fixed the unit test to not expect that
terminating NULL while verifying the result of these APIs.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
utest/tracefs-utest.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 04b5e81..d675c16 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -287,14 +287,14 @@ static void test_instance_ftrace_marker(struct tracefs_instance *instance)
CU_TEST(tracefs_printf(instance, "Test marker: %s 0x%X", string, data) == 0);
}
asprintf(&str, "Test marker: %s 0x%X", string, data);
- CU_TEST(find_test_marker(instance, str, strlen(str) + 1, MARKERS_WRITE_COUNT, false));
+ CU_TEST(find_test_marker(instance, str, strlen(str), MARKERS_WRITE_COUNT, false));
free(str);
for (i = 0; i < MARKERS_WRITE_COUNT; i++) {
CU_TEST(marker_vprint(instance, "Test marker V: %s 0x%X", string, data) == 0);
}
asprintf(&str, "Test marker V: %s 0x%X", string, data);
- CU_TEST(find_test_marker(instance, str, strlen(str) + 1, MARKERS_WRITE_COUNT, false));
+ CU_TEST(find_test_marker(instance, str, strlen(str), MARKERS_WRITE_COUNT, false));
free(str);
tracefs_print_close(instance);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-12 4:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-12 4:24 [PATCH 0/3] Fix unit tests and APIs for loading saved mappings Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 1/3] libtracefs: Fix trace options unit test Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 2/3] libtracefs: Fix loading of saved maps Tzvetomir Stoyanov (VMware)
2021-04-12 4:24 ` [PATCH 3/3] libtracefs: Fixed trace marker unit test Tzvetomir Stoyanov (VMware)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).