Brenden Blanco | 14915e0 | 2015-10-06 12:05:25 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) PLUMgrid, Inc. |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License") |
| 4 | |
| 5 | from bcc import BPF |
| 6 | from ctypes import c_int, c_ulonglong |
| 7 | import random |
| 8 | import time |
| 9 | from unittest import main, TestCase |
| 10 | |
| 11 | class TestArray(TestCase): |
| 12 | def test_simple(self): |
| 13 | b = BPF(text="""BPF_TABLE("array", int, u64, table1, 128);""") |
| 14 | t1 = b["table1"] |
| 15 | t1[c_int(0)] = c_ulonglong(100) |
| 16 | t1[c_int(127)] = c_ulonglong(1000) |
| 17 | for i, v in t1.items(): |
| 18 | if i.value == 0: |
| 19 | self.assertEqual(v.value, 100) |
| 20 | if i.value == 127: |
| 21 | self.assertEqual(v.value, 1000) |
| 22 | self.assertEqual(len(t1), 128) |
| 23 | |
| 24 | if __name__ == "__main__": |
| 25 | main() |