Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:lib\test_strscpy.c Create Date:2022-07-28 06:32:56
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:() - Run a specific test case.*@src: Source string, argument to strscpy_pad()*@count: Size of destination buffer, argument to strscpy_pad()*@expected: Expected return value from call to strscpy_pad()

Proto:static int __init tc(char *src, int count, int expected, int chars, int terminator, int pad)

Type:int

Parameter:

TypeParameterName
char *src
intcount
intexpected
intchars
intterminator
intpad
38  POISON = 'z'
40  Kernel module for testing 'strscpy' family of functions.++
42  If Not src Then
43  pr_err("null source string not supported\n")
44  Return -1
47  memset(buf, POISON, size of buf )
49  max_count = size of buf - 2
50  max_expected = count - 1
51  If count > max_count Then
52  pr_err("count (%d) is too big (%d) ... aborting", count, max_count)
53  Return -1
55  If expected > max_expected Then
56  pr_warn("expected (%d) is bigger than can possibly be returned (%d)", expected, max_expected)
60  written = strscpy_pad() - Copy a C-string into a sized buffer*@dest: Where to copy the string to*@src: Where to copy the string from*@count: Size of destination buffer* Copy the string, or as much of it as fits, into the dest buffer. The
61  If written != expected Then
62  pr_err("%d != %d (written, expected)\n", written, expected)
63  Go to fail
66  If count && written == -E2BIG Then
67  If strncmp(buf, src, count - 1) != 0 Then
68  pr_err("buffer state invalid for -E2BIG\n")
69  Go to fail
71  If buf[count - 1] != '\0' Then
72  pr_err("too big string is not null terminated correctly\n")
73  Go to fail
77  When i < chars cycle
78  If buf[i] != src[i] Then
79  pr_err("buf[i]==%c != src[i]==%c\n", buf[i], src[i])
80  Go to fail
84  If terminator Then
85  If buf[count - 1] != '\0' Then
86  pr_err("string is not null terminated correctly\n")
87  Go to fail
91  When i < pad cycle
92  index = chars + terminator + i
93  If buf[index] != '\0' Then
94  pr_err("padding missing at index: %d\n", i)
95  Go to fail
99  nr_bytes_poison = size of buf - chars - terminator - pad
100  When i < nr_bytes_poison cycle
101  index = size of buf - 1 - i
102  If buf[index] != POISON Then
103  pr_err("poison value missing at index: %d\n", i)
104  Go to fail
108  Return 0
109  fail :
110  failed_tests++
111  Return -1
Caller
NameDescribe
selftest