tools/testing/kunit/kunit_tool_test.py

Source file repositories/reference/linux-study-clean/tools/testing/kunit/kunit_tool_test.py

File Facts

System
Linux kernel
Corpus path
tools/testing/kunit/kunit_tool_test.py
Extension
.py
Size
43000 bytes
Lines
1040
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
#
# A collection of tests for tools/testing/kunit/kunit.py
#
# Copyright (C) 2019, Google LLC.
# Author: Brendan Higgins <brendanhiggins@google.com>

import unittest
from unittest import mock

import tempfile, shutil # Handling test_tmpdir

import io
import itertools
import json
import os
import signal
import subprocess
import sys
from typing import Iterable

import kunit_config
import kunit_parser
import kunit_kernel
import kunit_json
import kunit_junit
import kunit
from kunit_printer import stdout

test_tmpdir = ''
abs_test_data_dir = ''

def setUpModule():
	global test_tmpdir, abs_test_data_dir
	test_tmpdir = tempfile.mkdtemp()
	abs_test_data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'test_data'))

def tearDownModule():
	shutil.rmtree(test_tmpdir)

def _test_data_path(path):
	return os.path.join(abs_test_data_dir, path)

class KconfigTest(unittest.TestCase):

	def test_is_subset_of(self):
		kconfig0 = kunit_config.Kconfig()
		self.assertTrue(kconfig0.is_subset_of(kconfig0))

		kconfig1 = kunit_config.Kconfig()
		kconfig1.add_entry('TEST', 'y')
		self.assertTrue(kconfig1.is_subset_of(kconfig1))
		self.assertTrue(kconfig0.is_subset_of(kconfig1))
		self.assertFalse(kconfig1.is_subset_of(kconfig0))

	def test_read_from_file(self):
		kconfig_path = _test_data_path('test_read_from_file.kconfig')

		kconfig = kunit_config.parse_file(kconfig_path)

		expected_kconfig = kunit_config.Kconfig()
		expected_kconfig.add_entry('UML', 'y')
		expected_kconfig.add_entry('MMU', 'y')
		expected_kconfig.add_entry('TEST', 'y')
		expected_kconfig.add_entry('EXAMPLE_TEST', 'y')
		expected_kconfig.add_entry('MK8', 'n')

		self.assertEqual(kconfig, expected_kconfig)

Annotation

Implementation Notes