Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/test_min_heap: add test for heap_del()

Add test cases for the min_heap_del() to ensure its functionality is
thoroughly tested.

Link: https://lkml.kernel.org/r/20240524152958.919343-15-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Bagas Sanjaya <bagasdotme@gmail.com>
Cc: Brian Foster <bfoster@redhat.com>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Coly Li <colyli@suse.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matthew Sakai <msakai@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
7099f74d e596930f

+36
+36
lib/test_min_heap.c
··· 165 165 return err; 166 166 } 167 167 168 + static __init int test_heap_del(bool min_heap) 169 + { 170 + int values[] = { 3, 1, 2, 4, 0x8000000, 0x7FFFFFF, 0, 171 + -3, -1, -2, -4, 0x8000000, 0x7FFFFFF }; 172 + struct min_heap_test heap; 173 + 174 + min_heap_init(&heap, values, ARRAY_SIZE(values)); 175 + heap.nr = ARRAY_SIZE(values); 176 + struct min_heap_callbacks funcs = { 177 + .less = min_heap ? less_than : greater_than, 178 + .swp = swap_ints, 179 + }; 180 + int i, err; 181 + 182 + /* Test with known set of values. */ 183 + min_heapify_all(&heap, &funcs, NULL); 184 + for (i = 0; i < ARRAY_SIZE(values) / 2; i++) 185 + min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); 186 + err = pop_verify_heap(min_heap, &heap, &funcs); 187 + 188 + 189 + /* Test with randomly generated values. */ 190 + heap.nr = ARRAY_SIZE(values); 191 + for (i = 0; i < heap.nr; i++) 192 + values[i] = get_random_u32(); 193 + min_heapify_all(&heap, &funcs, NULL); 194 + 195 + for (i = 0; i < ARRAY_SIZE(values) / 2; i++) 196 + min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); 197 + err += pop_verify_heap(min_heap, &heap, &funcs); 198 + 199 + return err; 200 + } 201 + 168 202 static int __init test_min_heap_init(void) 169 203 { 170 204 int err = 0; ··· 209 175 err += test_heap_push(false); 210 176 err += test_heap_pop_push(true); 211 177 err += test_heap_pop_push(false); 178 + err += test_heap_del(true); 179 + err += test_heap_del(false); 212 180 if (err) { 213 181 pr_err("test failed with %d errors\n", err); 214 182 return -EINVAL;