~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/damon/tests/dbgfs-kunit.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /mm/damon/tests/dbgfs-kunit.h (Version linux-6.12-rc7) and /mm/damon/tests/dbgfs-kunit.h (Version linux-6.7.12)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 
  2 /*                                                
  3  * DAMON Debugfs Interface Unit Tests             
  4  *                                                
  5  * Author: SeongJae Park <sj@kernel.org>          
  6  */                                               
  7                                                   
  8 #ifdef CONFIG_DAMON_DBGFS_KUNIT_TEST              
  9                                                   
 10 #ifndef _DAMON_DBGFS_TEST_H                       
 11 #define _DAMON_DBGFS_TEST_H                       
 12                                                   
 13 #include <kunit/test.h>                           
 14                                                   
 15 static void damon_dbgfs_test_str_to_ints(struc    
 16 {                                                 
 17         char *question;                           
 18         int *answers;                             
 19         int expected[] = {12, 35, 46};            
 20         ssize_t nr_integers = 0, i;               
 21                                                   
 22         question = "123";                         
 23         answers = str_to_ints(question, strlen    
 24         KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_i    
 25         KUNIT_EXPECT_EQ(test, 123, answers[0])    
 26         kfree(answers);                           
 27                                                   
 28         question = "123abc";                      
 29         answers = str_to_ints(question, strlen    
 30         KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_i    
 31         KUNIT_EXPECT_EQ(test, 123, answers[0])    
 32         kfree(answers);                           
 33                                                   
 34         question = "a123";                        
 35         answers = str_to_ints(question, strlen    
 36         KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_i    
 37         kfree(answers);                           
 38                                                   
 39         question = "12 35";                       
 40         answers = str_to_ints(question, strlen    
 41         KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_i    
 42         for (i = 0; i < nr_integers; i++)         
 43                 KUNIT_EXPECT_EQ(test, expected    
 44         kfree(answers);                           
 45                                                   
 46         question = "12 35 46";                    
 47         answers = str_to_ints(question, strlen    
 48         KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_i    
 49         for (i = 0; i < nr_integers; i++)         
 50                 KUNIT_EXPECT_EQ(test, expected    
 51         kfree(answers);                           
 52                                                   
 53         question = "12 35 abc 46";                
 54         answers = str_to_ints(question, strlen    
 55         KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_i    
 56         for (i = 0; i < 2; i++)                   
 57                 KUNIT_EXPECT_EQ(test, expected    
 58         kfree(answers);                           
 59                                                   
 60         question = "";                            
 61         answers = str_to_ints(question, strlen    
 62         KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_i    
 63         kfree(answers);                           
 64                                                   
 65         question = "\n";                          
 66         answers = str_to_ints(question, strlen    
 67         KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_i    
 68         kfree(answers);                           
 69 }                                                 
 70                                                   
 71 static void damon_dbgfs_test_set_targets(struc    
 72 {                                                 
 73         struct damon_ctx *ctx = dbgfs_new_ctx(    
 74         char buf[64];                             
 75                                                   
 76         if (!damon_is_registered_ops(DAMON_OPS    
 77                 dbgfs_destroy_ctx(ctx);           
 78                 kunit_skip(test, "PADDR not re    
 79         }                                         
 80                                                   
 81         /* Make DAMON consider target has no p    
 82         damon_select_ops(ctx, DAMON_OPS_PADDR)    
 83                                                   
 84         dbgfs_set_targets(ctx, 0, NULL);          
 85         sprint_target_ids(ctx, buf, 64);          
 86         KUNIT_EXPECT_STREQ(test, (char *)buf,     
 87                                                   
 88         dbgfs_set_targets(ctx, 1, NULL);          
 89         sprint_target_ids(ctx, buf, 64);          
 90         KUNIT_EXPECT_STREQ(test, (char *)buf,     
 91                                                   
 92         dbgfs_set_targets(ctx, 0, NULL);          
 93         sprint_target_ids(ctx, buf, 64);          
 94         KUNIT_EXPECT_STREQ(test, (char *)buf,     
 95                                                   
 96         dbgfs_destroy_ctx(ctx);                   
 97 }                                                 
 98                                                   
 99 static void damon_dbgfs_test_set_init_regions(    
100 {                                                 
101         struct damon_ctx *ctx = damon_new_ctx(    
102         /* Each line represents one region in     
103         char * const valid_inputs[] = {"1 10 2    
104                 "1 10 20\n",                      
105                 "1 10 20\n0 39 59\n0 70 134\n     
106                 ""};                              
107         /* Reading the file again will show so    
108         char * const valid_expects[] = {"1 10     
109                 "1 10 20\n",                      
110                 "0 39 59\n0 70 134\n1 10 20\n1    
111                 ""};                              
112         char * const invalid_inputs[] = {"3 10    
113                 "1 10 20\n 1 14 26\n",            
114                 "0 10 20\n1 30 40\n 0 5 8"};      
115         char *input, *expect;                     
116         int i, rc;                                
117         char buf[256];                            
118                                                   
119         if (!damon_is_registered_ops(DAMON_OPS    
120                 damon_destroy_ctx(ctx);           
121                 kunit_skip(test, "PADDR not re    
122         }                                         
123                                                   
124         damon_select_ops(ctx, DAMON_OPS_PADDR)    
125                                                   
126         dbgfs_set_targets(ctx, 3, NULL);          
127                                                   
128         /* Put valid inputs and check the resu    
129         for (i = 0; i < ARRAY_SIZE(valid_input    
130                 input = valid_inputs[i];          
131                 expect = valid_expects[i];        
132                                                   
133                 rc = set_init_regions(ctx, inp    
134                 KUNIT_EXPECT_EQ(test, rc, 0);     
135                                                   
136                 memset(buf, 0, 256);              
137                 sprint_init_regions(ctx, buf,     
138                                                   
139                 KUNIT_EXPECT_STREQ(test, (char    
140         }                                         
141         /* Put invalid inputs and check the re    
142         for (i = 0; i < ARRAY_SIZE(invalid_inp    
143                 input = invalid_inputs[i];        
144                 pr_info("input: %s\n", input);    
145                 rc = set_init_regions(ctx, inp    
146                 KUNIT_EXPECT_EQ(test, rc, -EIN    
147                                                   
148                 memset(buf, 0, 256);              
149                 sprint_init_regions(ctx, buf,     
150                                                   
151                 KUNIT_EXPECT_STREQ(test, (char    
152         }                                         
153                                                   
154         dbgfs_set_targets(ctx, 0, NULL);          
155         damon_destroy_ctx(ctx);                   
156 }                                                 
157                                                   
158 static struct kunit_case damon_test_cases[] =     
159         KUNIT_CASE(damon_dbgfs_test_str_to_int    
160         KUNIT_CASE(damon_dbgfs_test_set_target    
161         KUNIT_CASE(damon_dbgfs_test_set_init_r    
162         {},                                       
163 };                                                
164                                                   
165 static struct kunit_suite damon_test_suite = {    
166         .name = "damon-dbgfs",                    
167         .test_cases = damon_test_cases,           
168 };                                                
169 kunit_test_suite(damon_test_suite);               
170                                                   
171 #endif /* _DAMON_TEST_H */                        
172                                                   
173 #endif  /* CONFIG_DAMON_KUNIT_TEST */             
174                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php