Skip to contentSkip to conversation

selftests: Add version file to kselftest installation dir

PATCH Superseded Tianyi Cui 2 participants 6 messages May 29, 2025 – Jun 10, 2025 Kselftest

lore
Share & tools
lore

Tianyi Cui

author
#0 lore raw

PATCH 1/1 selftests: Add version file to kselftest installation dir

As titled, adding version file to kselftest installation dir, so the user of the tarball can know which kernel version the tarball belongs to.

---
 tools/testing/selftests/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/Makefile +6 -0
index a0a6ba47d600..246e9863b45b 100644
@@ -291,6 +291,12 @@ ifdef INSTALL_PATH
 		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
 			-C $$TARGET emit_tests >> $(TEST_LIST); \
 	done;
+	@if git describe HEAD > /dev/null 2>&1; then \
+		git describe HEAD > $(INSTALL_PATH)/VERSION; \
+		printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
+	else \
+		printf "Unable to get version from git describe\n"; \
+	fi
 else
 	$(error Error: set INSTALL_PATH to use install)
 endif
Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 15 lines · Tianyi Cui

As titled, adding version file to kselftest installation dir, so the user of the tarball can know which kernel version the tarball belongs to.

---
  tools/testing/selftests/Makefile | 6 ++++++
  1 file changed, 6 insertions(+)
tools/testing/selftests/Makefile +0 -0
index a0a6ba47d600..246e9863b45b 100644
@@ -291,6 +291,12 @@ ifdef INSTALL_PATH
  		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
  			-C $$TARGET emit_tests >> $(TEST_LIST); \

tools/testing/selftests/Makefile ifdef INSTALL_PATH · line 302

Quoted 10 lines
tools/testing/selftests/Makefile +6 -0
  	done;
+	@if git describe HEAD > /dev/null 2>&1; then \
+		git describe HEAD > $(INSTALL_PATH)/VERSION; \
+		printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
+	else \
+		printf "Unable to get version from git describe\n"; \
+	fi
  else
  	$(error Error: set INSTALL_PATH to use install)
  endif

Why not use "make kernelrelease" to get the version?

thanks,
-- Shuah

author
#2 lore raw
Quoted 22 lines · Shuah Khan
Quoted 21 lines · Tianyi Cui

As titled, adding version file to kselftest installation dir, so the user of the tarball can know which kernel version the tarball belongs to.

---
  tools/testing/selftests/Makefile | 6 ++++++

  1 file changed, 6 insertions(+)
tools/testing/ renamed from tools/testing/selftests/Makefile +0 -0

selftests/Makefile
index a0a6ba47d600..246e9863b45b 100644

tools/testing/selftests/Makefile +0 -0
@@ -291,6 +291,12 @@ ifdef INSTALL_PATH

          $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
              -C $$TARGET emit_tests >> $(TEST_LIST); \
      done;
+    @if git describe HEAD > /dev/null 2>&1; then \
+        git describe HEAD > $(INSTALL_PATH)/VERSION; \
+        printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \

Quoted 8 lines
Quoted 6 lines

+    else \
+        printf "Unable to get version from git describe\n"; \
+    fi
  else
      $(error Error: set INSTALL_PATH to use install) endif

Why not use "make kernelrelease" to get the version?

Thank you for your attention for my first patch! There are mainly two reasons:

1. We'd like to have the VERSION file written to to the tarball. This
is because driver hardware tests needs to be run on specific hardware so that tarball is copied onto the DUT and we can compare the running kernel version and the test version.make kernelrelease only print it on screen, so we still need a way to store it into the tarball.

2. make kernelrelease requires the kernel repo to be configured and
prepared, while make -C tools/testing/selftests can run standalone. As a result, I don't want above to depend on make kernelrelease, which may break compatibility of people's existing CI systems.

Quoted 2 lines

thanks,
-- Shuah

maintainer
#3 lore raw
Quoted 10 lines · Tianyi Cui
Quoted 9 lines · Shuah Khan
Quoted 8 lines · Tianyi Cui

As titled, adding version file to kselftest installation dir, so the user of the tarball can know which kernel version the tarball belongs to.

---
   tools/testing/selftests/Makefile | 6 ++++++
   1 file changed, 6 insertions(+)
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
tools/testing/ renamed from tools/testing/selftests/Makefile +0 -0

selftests/Makefile
index a0a6ba47d600..246e9863b45b 100644

tools/testing/selftests/Makefile +0 -0
@@ -291,6 +291,12 @@ ifdef INSTALL_PATH
           $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET
Quoted 8 lines

tools/testing/selftests/Makefile ifdef INSTALL_PATH · line 298

Quoted 8 lines
tools/testing/selftests/Makefile +5 -0
 COLLECTION=$$TARGET \
               -C $$TARGET emit_tests >> $(TEST_LIST); \
       done;
+    @if git describe HEAD > /dev/null 2>&1; then \
+        git describe HEAD > $(INSTALL_PATH)/VERSION; \
+        printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
+    else \
+        printf "Unable to get version from git describe\n"; \

How does "git describe HEAD" here in this path?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tools/testing/selftests/Makefile +1 -0
+    fi
   else
       $(error Error: set INSTALL_PATH to use install)

  endif

Quoted 8 lines
Quoted 1 line

Why not use "make kernelrelease" to get the version?

Thank you for your attention for my first patch! There are mainly two reasons:

1. We'd like to have the VERSION file written to to the tarball. This
is because driver hardware tests needs to be run on specific hardware so that tarball is copied onto the DUT and we can compare the running

Okay - you want to save the version in tarball. No problem there.

Quoted 2 lines

kernel version and the test version.make kernelrelease only print it on screen,

This doesn't make sense to me. "git describe HEAD" also prints it on the screen.

so we still need a way to store it into the tarball.

You can do the same thing you are doing running "git describe HEAD" and create VERSION file?

Quoted 5 lines

2. make kernelrelease requires the kernel repo to be configured and
prepared, while make -C tools/testing/selftests can run standalone. As a result, I don't want above to depend on make kernelrelease, which may break compatibility of people's existing CI systems.

Yes "make kernelrelease" requires repo to be set up.

thanks,
-- Shuah

author
#4 lore raw

PATCH v2 1/1 selftests: Add version file to kselftest

Thanks for your patience for review! I've updated the patch to make it easier to understand. Specifically, stdout of git describe is stored into VERSION variable, then write into VERSION file rather than print on-screen. Please refer below for the sample output and the content in VERSION.

```
Emit Tests for drivers/net
Skipping non-existent dir: drivers/net/hw
Version saved to /tmp/ksft-net-drv/VERSION
make: Leaving directory
'/home/tianyicui/test/nipa/net-next/tools/testing/selftests'
➜  net-next git:(add_kversion) ✗ cat /tmp/ksft-net-drv/VERSION
v6.15-12423-g7ebe76e39b4c
```
author
#5 lore raw

PATCH v2 1/1 selftests: Add version file to kselftest installation dir

As titled, adding version file to kselftest installation dir, so the user of the tarball can know which kernel version the tarball belongs to.

---
 tools/testing/selftests/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/Makefile +7 -0
index 339b31e6a6b5..9dae84a74e7f 100644
@@ -293,6 +293,13 @@ ifdef INSTALL_PATH
 		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
 			-C $$TARGET emit_tests >> $(TEST_LIST); \
 	done;
+	@VERSION=$$(git describe HEAD 2>/dev/null); \
+	if [ -n "$$VERSION" ]; then \
+		echo "$$VERSION" > $(INSTALL_PATH)/VERSION; \
+		printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
+	else \
+		printf "Unable to get version from git describe\n"; \
+	fi
 else
 	$(error Error: set INSTALL_PATH to use install)
 endif
Signature · 1 line
2.47.1