Skip to content

Conversation

@georgejguo
Copy link

@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
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.

Tested-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
@georgejguo georgejguo reopened this Nov 18, 2025
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