mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	Change KUnit test output to better comply with KTAP v1 specifications found here: https://kernel.org/doc/html/latest/dev-tools/ktap.html. 1) Use "KTAP version 1" instead of "TAP version 14" as test output header 2) Remove '-' between test number and test name on test result lines 2) Add KTAP version lines to each subtest header as well Note that the new KUnit output still includes the “# Subtest” line now located after the KTAP version line. This does not completely match the KTAP v1 spec but since it is classified as a diagnostic line, it is not expected to be disruptive or break any existing parsers. This “# Subtest” line comes from the TAP 14 spec (https://testanything.org/tap-version-14-specification.html) and it is used to define the test name before the results. Original output: TAP version 14 1..1 # Subtest: kunit-test-suite 1..3 ok 1 - kunit_test_1 ok 2 - kunit_test_2 ok 3 - kunit_test_3 # kunit-test-suite: pass:3 fail:0 skip:0 total:3 # Totals: pass:3 fail:0 skip:0 total:3 ok 1 - kunit-test-suite New output: KTAP version 1 1..1 KTAP version 1 # Subtest: kunit-test-suite 1..3 ok 1 kunit_test_1 ok 2 kunit_test_2 ok 3 kunit_test_3 # kunit-test-suite: pass:3 fail:0 skip:0 total:3 # Totals: pass:3 fail:0 skip:0 total:3 ok 1 kunit-test-suite Signed-off-by: Rae Moar <rmoar@google.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Tested-by: Anders Roxell <anders.roxell@linaro.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
		
			
				
	
	
		
			116 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			116 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0
 | 
						|
/*
 | 
						|
 * Copyright (c) 2020, Oracle and/or its affiliates.
 | 
						|
 *    Author: Alan Maguire <alan.maguire@oracle.com>
 | 
						|
 */
 | 
						|
 | 
						|
#include <linux/debugfs.h>
 | 
						|
#include <linux/module.h>
 | 
						|
 | 
						|
#include <kunit/test.h>
 | 
						|
 | 
						|
#include "string-stream.h"
 | 
						|
 | 
						|
#define KUNIT_DEBUGFS_ROOT             "kunit"
 | 
						|
#define KUNIT_DEBUGFS_RESULTS          "results"
 | 
						|
 | 
						|
/*
 | 
						|
 * Create a debugfs representation of test suites:
 | 
						|
 *
 | 
						|
 * Path						Semantics
 | 
						|
 * /sys/kernel/debug/kunit/<testsuite>/results	Show results of last run for
 | 
						|
 *						testsuite
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
static struct dentry *debugfs_rootdir;
 | 
						|
 | 
						|
void kunit_debugfs_cleanup(void)
 | 
						|
{
 | 
						|
	debugfs_remove_recursive(debugfs_rootdir);
 | 
						|
}
 | 
						|
 | 
						|
void kunit_debugfs_init(void)
 | 
						|
{
 | 
						|
	if (!debugfs_rootdir)
 | 
						|
		debugfs_rootdir = debugfs_create_dir(KUNIT_DEBUGFS_ROOT, NULL);
 | 
						|
}
 | 
						|
 | 
						|
static void debugfs_print_result(struct seq_file *seq,
 | 
						|
				 struct kunit_suite *suite,
 | 
						|
				 struct kunit_case *test_case)
 | 
						|
{
 | 
						|
	if (!test_case || !test_case->log)
 | 
						|
		return;
 | 
						|
 | 
						|
	seq_printf(seq, "%s", test_case->log);
 | 
						|
}
 | 
						|
 | 
						|
/*
 | 
						|
 * /sys/kernel/debug/kunit/<testsuite>/results shows all results for testsuite.
 | 
						|
 */
 | 
						|
static int debugfs_print_results(struct seq_file *seq, void *v)
 | 
						|
{
 | 
						|
	struct kunit_suite *suite = (struct kunit_suite *)seq->private;
 | 
						|
	enum kunit_status success = kunit_suite_has_succeeded(suite);
 | 
						|
	struct kunit_case *test_case;
 | 
						|
 | 
						|
	if (!suite || !suite->log)
 | 
						|
		return 0;
 | 
						|
 | 
						|
	seq_printf(seq, "%s", suite->log);
 | 
						|
 | 
						|
	kunit_suite_for_each_test_case(suite, test_case)
 | 
						|
		debugfs_print_result(seq, suite, test_case);
 | 
						|
 | 
						|
	seq_printf(seq, "%s %d %s\n",
 | 
						|
		   kunit_status_to_ok_not_ok(success), 1, suite->name);
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
static int debugfs_release(struct inode *inode, struct file *file)
 | 
						|
{
 | 
						|
	return single_release(inode, file);
 | 
						|
}
 | 
						|
 | 
						|
static int debugfs_results_open(struct inode *inode, struct file *file)
 | 
						|
{
 | 
						|
	struct kunit_suite *suite;
 | 
						|
 | 
						|
	suite = (struct kunit_suite *)inode->i_private;
 | 
						|
 | 
						|
	return single_open(file, debugfs_print_results, suite);
 | 
						|
}
 | 
						|
 | 
						|
static const struct file_operations debugfs_results_fops = {
 | 
						|
	.open = debugfs_results_open,
 | 
						|
	.read = seq_read,
 | 
						|
	.llseek = seq_lseek,
 | 
						|
	.release = debugfs_release,
 | 
						|
};
 | 
						|
 | 
						|
void kunit_debugfs_create_suite(struct kunit_suite *suite)
 | 
						|
{
 | 
						|
	struct kunit_case *test_case;
 | 
						|
 | 
						|
	/* Allocate logs before creating debugfs representation. */
 | 
						|
	suite->log = kzalloc(KUNIT_LOG_SIZE, GFP_KERNEL);
 | 
						|
	kunit_suite_for_each_test_case(suite, test_case)
 | 
						|
		test_case->log = kzalloc(KUNIT_LOG_SIZE, GFP_KERNEL);
 | 
						|
 | 
						|
	suite->debugfs = debugfs_create_dir(suite->name, debugfs_rootdir);
 | 
						|
 | 
						|
	debugfs_create_file(KUNIT_DEBUGFS_RESULTS, S_IFREG | 0444,
 | 
						|
			    suite->debugfs,
 | 
						|
			    suite, &debugfs_results_fops);
 | 
						|
}
 | 
						|
 | 
						|
void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
 | 
						|
{
 | 
						|
	struct kunit_case *test_case;
 | 
						|
 | 
						|
	debugfs_remove_recursive(suite->debugfs);
 | 
						|
	kfree(suite->log);
 | 
						|
	kunit_suite_for_each_test_case(suite, test_case)
 | 
						|
		kfree(test_case->log);
 | 
						|
}
 |