blob: f83203f106a8f8702abf8ce0b08daa4786758708 [file] [log] [blame]
Brenden Blanco14915e02015-10-06 12:05:25 -07001#!/usr/bin/env python
2# Copyright (c) PLUMgrid, Inc.
3# Licensed under the Apache License, Version 2.0 (the "License")
4
5from bcc import BPF
6from ctypes import c_int, c_ulonglong
7import random
8import time
9from unittest import main, TestCase
10
11class 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
24if __name__ == "__main__":
25 main()