Skip to content

Conversation

@georgejguo
Copy link
Contributor

@georgejguo georgejguo commented Dec 11, 2024

Hi Joe,

Would you be willing to generate a set of unit test object files (see https://github.com/dynup/kpatch-unit-test-objs where we > keep those for various arches. I can walk you through how to generate them.)

I m here now.
Could u tell me how to generate and do unit tests. You can take x86_64 as an example.

Thanks!

@joe-lawrence
Copy link
Contributor

Hi @georgejguo : the unit tests are created somewhat ad-hoc. For new arches, we usually start with the object files generated by the integration tests. You'll need to build with kpatch-build -d to keep the intermediate original and patched object files in place. Those files are stripped with strip --strip-debug --keep-file-symbols --remove-section=.eh_frame and then a corresponding .test file is created. The test can check things with readelf/objdump or just use nm to figure out how many new functions end up in the output file (see the assert_num_funcs() function).

@georgejguo
Copy link
Contributor Author

Hi, Joe

Those files are stripped with strip --strip-debug --keep-file-symbols --remove-section=.eh_frame and then a corresponding .test file is created.
I am still confued how to do that.

This is my steps for producing unit test object files:
1)
[george@fedora kpatch-build]$ ./kpatch-build -d -s ~/linux/ -c ~/linux/.config -v ~/linux/vmlinux ~/linux/0001-patched-tcp_sendmsg.patch --skip-gcc-check
2)
[george@fedora kpatch-build]$ cd ~/.kpatch/tmp
[george@fedora tmp]$ ls
changed_objs kernel-backup kpatch-build.env Module.symvers new_symbols orig output patch patched undefined_references vmlinux.symtab
3)
[george@fedora tmp]$ strip --strip-debug --keep-file-symbols --remove-section=.eh_frame orig/net/ipv4/tcp.o

@joe-lawrence
Copy link
Contributor

Hi @georgejguo - that looks about right. I'd go through the integration tests one-by-one (or script it) to generate original / patched object files and then drop them into an arch directory with a few updates:

Makefile
-- Setup CDO_ENV (create-diff-object environment variables), you can
grep these from ~/.kpatch/tmp/kpatch-build.env

.ORIG.o
-- Copy this from ~/.kpatch/tmp/orig/... and strip

.PATCHED.o
-- Copy this from ~/.kpatch/tmp/new/... and strip

.test
-- If applicable, this is just a small bash script to verify the
resulting .OUTPUT.o during the unit test.

The $KPATCH_TEST_LIBRARY (test-functions.sh) includes an
assert_num_funcs function that run the nm command to verify the
number of functions present in the output file. Most tests simply
verify this.

Tests can check other things as well, see the x86_64 tests:
- convert-global-local.test
- mcount_loc-issue-1102.test
- zero-page-rela-issue-1064.test
that invoke further checks like readelf, etc.

Modeling after #51 should get you most of the way there.

Add object files generated from test cases in the examples/
and test/integration/rhel-9.6/ directories to serve as unit tests.

 $ git describe HEAD
 v6.15-rc2-278-gfc96b232f8e7

 $ gcc --version
 gcc (GCC) 14.2.1 20241104 (Red Hat 14.2.1-6)

The kernel config was based on:

 - config-6.15.0-0.rc2.20250418gitfc96b232f8e7.25.fc42.loongarch64
 - CONFIG_FTRACE=y
 - CONFIG_FUNCTION_TRACER=y
 - CONFIG_LIVEPATCH=y
 - CONFIG_MODULE_ALLOW_BTF_MISMATCH=y

Tested-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
@georgejguo
Copy link
Contributor Author

Hi @joe-lawrence

what do you think this time ?
Is there any left work I need do?

Copy link
Contributor

@joe-lawrence joe-lawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @georgejguo. I think this looks good, but let me take a look at the PR over on the main project before merging this one.

@joe-lawrence joe-lawrence merged commit bf46364 into dynup:master Dec 23, 2025
@joe-lawrence
Copy link
Contributor

Thanks, George Guo and Kexin Liu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants