added u64 testcase
authorZaafar Ahmed <zaafar.tahir@gmail.com>
Tue, 29 Mar 2016 20:46:26 +0000 (01:46 +0500)
committerZaafar Ahmed <zaafar.tahir@gmail.com>
Tue, 29 Mar 2016 20:46:26 +0000 (01:46 +0500)
tests/python/test_percpu.py

index b747577..fa5539d 100755 (executable)
@@ -8,6 +8,35 @@ import unittest as ut
 
 class TestPercpu(ut.TestCase):
 
+    def test_u64(self):
+        test_prog1 = """
+        BPF_TABLE("pc_hash", u32, u64, stats, 1);
+        int hello_world(void *ctx) {
+            u32 key=0;
+            u64 value = 0, *val;
+            val = stats.lookup_or_init(&key, &value);
+            *val += 1;
+            return 0;
+        }
+        """
+        self.addCleanup(self.cleanup)
+        bpf_code = BPF(text=test_prog1)
+        stats_map = bpf_code.get_table("stats")
+        bpf_code.attach_kprobe(event="sys_clone", fn_name="hello_world")
+        sleep(1)
+        self.assertEqual(len(stats_map),1)
+        for x in range(0, 10):
+            ini = stats_map.Leaf(0,0,0,0,0,0,0,0)
+            stats_map[ stats_map.Key(0) ] = ini
+            sleep(1)
+            k = stats_map[ stats_map.Key(0) ]
+            x = stats_map.sum(stats_map.Key(0))
+            y = stats_map.average(stats_map.Key(0))
+            z = stats_map.max(stats_map.Key(0))
+            print (x.value)
+            self.assertGreater(x.value, 1L)
+            self.assertGreater(z.value, 1L)
+
     def test_u32(self):
         test_prog1 = """
         BPF_TABLE("pc_array", u32, u32, stats, 1);