summaryrefstree
path: root/kernel/test/kunit_manager.c
blob: 08bf1cc65ac91bd1408b91a619a645a7846f6b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* kunit_manager.c
 *
 * Driver to manage kunit
 *
 * Copyright (C) 2019 Samsung Electronics
 *
 * Sangsu Ha <sangsu.ha@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <kunit/kunit_manager.h>

extern int test_executor_init(void);

static ssize_t kunit_manager_run_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	if (!strncmp(buf, "1", 1)) {
		test_executor_init();
	}
	return count;
}
static DEVICE_ATTR(run, 0200, NULL, kunit_manager_run_store);

static struct attribute *kunit_manager_attributes[] = {
	&dev_attr_run.attr,
	NULL,
};

static struct attribute_group kunit_manager_attr_group = {
	.attrs = kunit_manager_attributes,
};

static int __init kunit_manager_init(void)
{
	struct kunit_manager_data *data;
	int ret;

	data = kzalloc(sizeof(struct kunit_manager_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;


	data->dev = sec_device_create(data, "sec_kunit");
	if (IS_ERR(data->dev)) {
		pr_err("%s: Failed to create device!\n", __func__);
		ret = PTR_ERR(data->dev);
		goto err_sec_device_create;
	}

	dev_set_drvdata(data->dev, data);

	ret = sysfs_create_group(&data->dev->kobj, &kunit_manager_attr_group);
	if (ret < 0) {
		pr_err("%s: Failed to create sysfs group\n", __func__);
		goto err_sysfs_create_group;
	}

	pr_info("%s: Success\n", __func__);

	return 0;

err_sysfs_create_group:
	sec_device_destroy(data->dev->devt);
err_sec_device_create:
	kfree(data);

	return ret;
}

static void __exit kunit_manager_exit(void)
{
	return;
}

module_init(kunit_manager_init);
module_exit(kunit_manager_exit);

MODULE_DESCRIPTION("Samsung kunit manager driver");
MODULE_AUTHOR("Sangsu Ha <sangsu.ha@samsung.com>");
MODULE_LICENSE("GPL");