File: test_slkm.c

package info (click to toggle)
safeclib 3.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: ansic: 52,639; makefile: 1,271; perl: 528; sh: 518
file content (123 lines) | stat: -rw-r--r-- 4,404 bytes parent folder | download | duplicates (3)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*------------------------------------------------------------------
 * test_slkm.c - kernel unit tests for slkm
 *
 * 2012, Jonathan Toppins <jtoppins@users.sourceforge.net>
 *
 * Copyright (c) 2012 Cisco Systems, Inc.
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *------------------------------------------------------------------
 */

#include <linux/module.h>
#include <linux/kernel.h>

#define DRV_NAME "test-slkm"
#define DRV_VERSION "0.0"
#define DRV_DESCRIPTION "Safe C Library Kernel Module Unit Tests"
#define DRV_COPYRIGHT "Copyright(c) 2012 cisco Systems, Inc."

MODULE_DESCRIPTION(DRV_DESCRIPTION);
MODULE_AUTHOR(DRV_COPYRIGHT);
MODULE_LICENSE("MIT");
MODULE_VERSION(DRV_VERSION);
MODULE_ALIAS("test-slkm");

/*
 * // example match table... show how to properally mark the table
 *static const struct of_device_id _match[] __devinitconst = {
 *        {
 *                .compatible = "blah",
 *                .data       = (void *) (&_ops),
 *        },
 *        {},
 *};
 *MODULE_DEVICE_TABLE(of, _match);
 */

struct test_entry {
    int (*test_func)(void);
    char *name;
};

extern int test_memset_s(void);
extern int test_memcpy_s(void);
extern int test_memmove_s(void);
extern int test_memcmp_s(void);
extern int test_strcpy_s(void);
extern int test_strncpy_s(void);
extern int test_strcat_s(void);
extern int test_strncat_s(void);
extern int test_strcmp_s(void);
extern int test_strcasecmp_s(void);
extern int test_strstr_s(void);
extern int test_strnlen_s(void);
extern int test_strpbrk_s(void);
extern int test_strspn_s(void);
extern int test_strcspn_s(void);

/**
 * @brief Module initialization function.
 *
 * @return 0 on success; < 0 on failure
 */
static int __init testslkm_init(void) {
    int rc = 0;
    int i = 0;
    struct test_entry test_vec[] = {{test_memset_s, "test_memset_s"},
                                    {test_memcpy_s, "test_memcpy_s"},
                                    {test_memmove_s, "test_memmove_s"},
                                    {test_memcmp_s, "test_memcmp_s"},
                                    {test_strcpy_s, "test_strcpy_s"},
                                    {test_strncpy_s, "test_strncpy_s"},
                                    {test_strcat_s, "test_strcat_s"},
                                    {test_strncat_s, "test_strncat_s"},
                                    {test_strcmp_s, "test_strcmp_s"},
                                    {test_strcasecmp_s, "test_strcasecmp_s"},
                                    {test_strstr_s, "test_strstr_s"},
                                    {test_strnlen_s, "test_strnlen_s"},
                                    {test_strpbrk_s, "test_strpbrk_s"},
                                    {test_strspn_s, "test_strspn_s"},
                                    {test_strcspn_s, "test_strcspn_s"}};

    printk(KERN_INFO "%s, v%s - %s\n", DRV_DESCRIPTION, DRV_VERSION,
           DRV_COPYRIGHT);

    for (i = 0; i < ARRAY_SIZE(test_vec); i++) {
        rc = test_vec[i].test_func();
        if (rc)
            printk(KERN_INFO "%s tests failed\n", test_vec[i].name);
    }
    return rc;
}

/**
 * @brief Module exit function.
 */
static void __exit testslkm_exit(void) {
    printk(KERN_INFO "%s called\n", __func__);
}

/* Module entry and exit points */
module_init(testslkm_init);
module_exit(testslkm_exit);