Skip to content

Commit

Permalink
Add runtime test for parallel map accessing
Browse files Browse the repository at this point in the history
Signed-off-by: maokelong <chenjinglong1@huawei.com>
  • Loading branch information
maokelong committed May 27, 2023
1 parent 6a9bbf3 commit 41e485f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/runtime/basic
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ PROG BEGIN { @x = 10; printf("%d", @x++); printf(" %d", ++@x); printf(" %d", @x-
EXPECT 10 12 12 10
TIMEOUT 1

NAME parallel map access
RUN {{BPFTRACE}} runtime/scripts/parallel_map_access.bt
EXPECT SUCCESS
TIMEOUT 2

NAME increment/decrement variable
PROG BEGIN { $x = 10; printf("%d", $x++); printf(" %d", ++$x); printf(" %d", $x--); printf(" %d\n", --$x); exit(); }
EXPECT 10 12 12 10
Expand Down
24 changes: 24 additions & 0 deletions tests/runtime/scripts/parallel_map_access.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Regression testing the map's thread safety.
// Bpftrace shouldn't crash during map's print/clear/zero operations
// while delete is called at the same time.
//
// For more information, please refer to:
// https://github.com/iovisor/bpftrace/pull/2623

i:us:1 {
@data[rand % 100] = count();
if (rand % 5 == 0) {
delete(@data[rand % 10]);
}
}

i:ms:1 {
print(@data);
clear(@data);
zero(@data);
}

i:s:1 {
print("SUCCESS");
exit();
}

0 comments on commit 41e485f

Please sign in to comment.