Skip to contentSkip to conversation

kunit: Fix kunit.py run --build_dir='<foo>' fails on "unclean" trees

PATCH Superseded Vitor Massaru Iha 2 participants 3 messages Mar 30, 2020 – Mar 31, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kunit: Fix kunit.py run --build_dir='<foo>' fails on "unclean" trees

Fix this bug: https://bugzilla.kernel.org/show_bug.cgi?id=205219

For some reason, the environment variable ARCH is used instead of ARCH passed as an argument, this patch uses a copy of the env, but using ARCH=um and CROSS_COMPILER='' to avoid this problem.

This patch doesn't change the user's environment variables, avoiding side effects.

---
 tools/testing/kunit/kunit_kernel.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/kunit/kunit_kernel.py +7 -5
index d99ae75ef72f..0cb1f81ac8f2 100644
@@ -15,6 +15,7 @@ import kunit_config
 
 KCONFIG_PATH = '.config'
 kunitconfig_path = '.kunitconfig'
+env = dict(os.environ.copy(), ARCH='um', CROSS_COMPILE='')
 
 class ConfigError(Exception):
 	"""Represents an error trying to configure the Linux kernel."""
@@ -36,22 +37,22 @@ class LinuxSourceTreeOperations(object):
 			raise ConfigError(e.output)
 
 	def make_olddefconfig(self, build_dir):
-		command = ['make', 'ARCH=um', 'olddefconfig']
+		command = ['make', 'olddefconfig']
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
-			subprocess.check_output(command)
+			subprocess.check_output(command, env=env)
 		except OSError as e:
 			raise ConfigError('Could not call make command: ' + e)
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
 	def make(self, jobs, build_dir):
-		command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
+		command = ['make', '--jobs=' + str(jobs)]
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
-			subprocess.check_output(command)
+			subprocess.check_output(command, env=env)
 		except OSError as e:
 			raise BuildError('Could not call execute make: ' + e)
 		except subprocess.CalledProcessError as e:
@@ -66,7 +67,8 @@ class LinuxSourceTreeOperations(object):
 			[linux_bin] + params,
 			stdin=subprocess.PIPE,
 			stdout=subprocess.PIPE,
-			stderr=subprocess.PIPE)
+			stderr=subprocess.PIPE,
+			env=env)
 		process.wait(timeout=timeout)
 		return process
 
Signature · 1 line
2.21.1
#1 lore raw
Quoted 9 lines · Vitor Massaru Iha

Fix this bug: https://bugzilla.kernel.org/show_bug.cgi?id=205219

For some reason, the environment variable ARCH is used instead of ARCH passed as an argument, this patch uses a copy of the env, but using ARCH=um and CROSS_COMPILER='' to avoid this problem.

This patch doesn't change the user's environment variables, avoiding side effects.

Seems reasonable to me.

Quoted 1 line

I cannot test this as your patch doesn't apply to our for-next branch (kselftest/kunit). You can find it here:

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=kunit

Quoted 56 lines
---
 tools/testing/kunit/kunit_kernel.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/kunit/kunit_kernel.py +7 -6
index d99ae75ef72f..0cb1f81ac8f2 100644
@@ -15,6 +15,7 @@ import kunit_config
 
 KCONFIG_PATH = '.config'
 kunitconfig_path = '.kunitconfig'
+env = dict(os.environ.copy(), ARCH='um', CROSS_COMPILE='')
 
 class ConfigError(Exception):
        """Represents an error trying to configure the Linux kernel."""
@@ -36,22 +37,22 @@ class LinuxSourceTreeOperations(object):
                        raise ConfigError(e.output)
 
        def make_olddefconfig(self, build_dir):
-               command = ['make', 'ARCH=um', 'olddefconfig']
+               command = ['make', 'olddefconfig']
                if build_dir:
                        command += ['O=' + build_dir]
                try:
-                       subprocess.check_output(command)
+                       subprocess.check_output(command, env=env)
                except OSError as e:
                        raise ConfigError('Could not call make command: ' + e)
                except subprocess.CalledProcessError as e:
                        raise ConfigError(e.output)
 
        def make(self, jobs, build_dir):
-               command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
+               command = ['make', '--jobs=' + str(jobs)]
                if build_dir:
                        command += ['O=' + build_dir]
                try:
-                       subprocess.check_output(command)
+                       subprocess.check_output(command, env=env)
                except OSError as e:
                        raise BuildError('Could not call execute make: ' + e)
                except subprocess.CalledProcessError as e:
@@ -66,7 +67,8 @@ class LinuxSourceTreeOperations(object):
                        [linux_bin] + params,
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
-                       stderr=subprocess.PIPE)
+                       stderr=subprocess.PIPE,
+                       env=env)
                process.wait(timeout=timeout)
                return process
 
--

2.21.1

#2 lore raw

Hi Brendan,

Quoted 5 lines · Brendan Higgins' via KUnit Development
Quoted 3 lines · Vitor Massaru Iha

Fix this bug: https://bugzilla.kernel.org/show_bug.cgi?id=205219

Quoted 8 lines
Quoted 6 lines

For some reason, the environment variable ARCH is used instead of ARCH passed as an argument, this patch uses a copy of the env, but using ARCH=um and CROSS_COMPILER='' to avoid this problem.

This patch doesn't change the user's environment variables, avoiding side effects.

Seems reasonable to me.

There are other problems here, I'll fix it.

Quoted 69 lines
Quoted 2 lines

I cannot test this as your patch doesn't apply to our for-next branch (kselftest/kunit). You can find it here:

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=kunit

Quoted 54 lines
---
 tools/testing/kunit/kunit_kernel.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/kunit/kunit_kernel.py +7 -6
index d99ae75ef72f..0cb1f81ac8f2 100644
@@ -15,6 +15,7 @@ import kunit_config
 
 KCONFIG_PATH = '.config'
 kunitconfig_path = '.kunitconfig'
+env = dict(os.environ.copy(), ARCH='um', CROSS_COMPILE='')
 
 class ConfigError(Exception):
        """Represents an error trying to configure the Linux kernel."""
@@ -36,22 +37,22 @@ class LinuxSourceTreeOperations(object):
                        raise ConfigError(e.output)
 
        def make_olddefconfig(self, build_dir):
-               command = ['make', 'ARCH=um', 'olddefconfig']
+               command = ['make', 'olddefconfig']
                if build_dir:
                        command += ['O=' + build_dir]
                try:
-                       subprocess.check_output(command)
+                       subprocess.check_output(command, env=env)
                except OSError as e:
                        raise ConfigError('Could not call make command: ' + e)
                except subprocess.CalledProcessError as e:
                        raise ConfigError(e.output)
 
        def make(self, jobs, build_dir):
-               command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
+               command = ['make', '--jobs=' + str(jobs)]
                if build_dir:
                        command += ['O=' + build_dir]
                try:
-                       subprocess.check_output(command)
+                       subprocess.check_output(command, env=env)
                except OSError as e:
                        raise BuildError('Could not call execute make: ' + e)
                except subprocess.CalledProcessError as e:
@@ -66,7 +67,8 @@ class LinuxSourceTreeOperations(object):
                        [linux_bin] + params,
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
-                       stderr=subprocess.PIPE)
+                       stderr=subprocess.PIPE,
+                       env=env)
                process.wait(timeout=timeout)
                return process
 
--
Quoted 2 lines

2.21.1

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/CAFd5g47hiPf7Xy0f4YER%2BHzHHXyUV0dhiQ%3D2ZXfezEHBcrTuEQ%40mail.gmail.com.