kunit: tool: add support for building kernel with additional threads

Allows the user to specify how many threads to be used for building the
kernel as part of building and running tests.

Google-Bug-Id: 131440297
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
Change-Id: If1c10b7e122b5863b7e07f467c7008d3e6397336
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 5ba3a2a..9ba3a3e 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -15,7 +15,7 @@
 
 from collections import namedtuple
 
-KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout'])
+KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs'])
 
 KunitResult = namedtuple('KunitResult', ['status','result'])
 
@@ -36,7 +36,7 @@
 	print(kunit_parser.timestamp('Building KUnit Kernel ...'))
 
 	build_start = time.time()
-	build_result = linux.build_um_kernel()
+	build_result = linux.build_um_kernel(request.jobs)
 	build_end = time.time()
 	if build_result.status != kunit_kernel.BuildStatus.SUCCESS:
 		return KunitResult(KunitStatus.BUILD_FAILURE, build_result)
@@ -92,6 +92,11 @@
 				default=300,
 				metavar='timeout')
 
+	run_parser.add_argument('--jobs',
+				help='As in the make command, "Specifies  the number of '
+				'jobs (commands) to run simultaneously."',
+				type=int, default=8, metavar='jobs')
+
 	new_parser = subparser.add_parser(
 			'new',
 			help='Prints out boilerplate for writing new tests.')
@@ -112,7 +117,9 @@
 	if cli_args.subcommand == 'new':
 		print_test_skeletons(cli_args)
 	elif cli_args.subcommand == 'run':
-		request = KunitRequest(cli_args.raw_output, cli_args.timeout)
+		request = KunitRequest(cli_args.raw_output,
+				       cli_args.timeout,
+				       cli_args.jobs)
 		result = run_tests(linux, request)
 		if result.status == KunitStatus.TEST_FAILURE:
 			sys.exit(1)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 4b4cffb..1cbb2ee 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -50,9 +50,9 @@
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
-	def make(self):
+	def make(self, jobs):
 		try:
-			subprocess.check_output(['make', 'ARCH=um'])
+			subprocess.check_output(['make', 'ARCH=um', '--jobs=' + str(jobs)])
 		except OSError as e:
 			raise BuildError('Could not call execute make: ' + e)
 		except subprocess.CalledProcessError as e:
@@ -137,10 +137,10 @@
 			print('Generating .config ...')
 			return self.build_config()
 
-	def build_um_kernel(self):
+	def build_um_kernel(self, jobs):
 		try:
 			self._ops.make_olddefconfig()
-			self._ops.make()
+			self._ops.make(jobs)
 		except (ConfigError, BuildError) as e:
 			logging.error(e)
 			return BuildResult(BuildStatus.FAILURE, str(e))