<s> from bcc import BPF <EOL> import ctypes as ct <EOL> import random <EOL> import time <EOL> from unittest import main , TestCase <EOL> class TestArray ( TestCase ) : <EOL> def test_simple ( self ) : <EOL> b = BPF ( text = """<STR_LIT>""" ) <EOL> t1 = b [ "<STR_LIT>" ] <EOL> t1 [ ct . c_int ( <NUM_LIT:0> ) ] = ct . c_ulonglong ( <NUM_LIT:100> ) <EOL> t1 [ ct . c_int ( <NUM_LIT> ) ] = ct . c_ulonglong ( <NUM_LIT:1000> ) <EOL> for i , v in t1 . items ( ) : <EOL> if i . value == <NUM_LIT:0> : <EOL> self . assertEqual ( v . value , <NUM_LIT:100> ) <EOL> if i . value == <NUM_LIT> : <EOL> self . assertEqual ( v . value , <NUM_LIT:1000> ) <EOL> self . assertEqual ( len ( t1 ) , <NUM_LIT> ) <EOL> def test_native_type ( self ) : <EOL> b = BPF ( text = """<STR_LIT>""" ) <EOL> t1 = b [ "<STR_LIT>" ] <EOL> t1 [ <NUM_LIT:0> ] = ct . c_ulonglong ( <NUM_LIT:100> ) <EOL> t1 [ - <NUM_LIT:2> ] = ct . c_ulonglong ( <NUM_LIT> ) <EOL> t1 [ <NUM_LIT> ] = ct . c_ulonglong ( <NUM_LIT:1000> ) <EOL> for i , v in t1 . items ( ) : <EOL> if i . value == <NUM_LIT:0> : <EOL> self . assertEqual ( v . value , <NUM_LIT:100> ) <EOL> if i . value == <NUM_LIT> : <EOL> self . assertEqual ( v . value , <NUM_LIT:1000> ) <EOL> self . assertEqual ( len ( t1 ) , <NUM_LIT> ) <EOL> self . assertEqual ( t1 [ - <NUM_LIT:2> ] . value , <NUM_LIT> ) <EOL> self . assertEqual ( t1 [ - <NUM_LIT:1> ] . value , t1 [ <NUM_LIT> ] . value ) <EOL> def test_perf_buffer ( self ) : <EOL> self . counter = <NUM_LIT:0> <EOL> class Data ( ct . Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , ct . c_ulonglong ) ] <EOL> def cb ( cpu , data , size ) : <EOL> self . assertGreater ( size , ct . sizeof ( Data ) ) <EOL> event = ct . cast ( data , ct . POINTER ( Data ) ) . contents <EOL> self . counter += <NUM_LIT:1> <EOL> text = """<STR_LIT>""" <EOL> b = BPF ( text = text ) <EOL> b [ "<STR_LIT>" ] . open_perf_buffer ( cb ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> b . kprobe_poll ( ) <EOL> self . assertGreater ( self . counter , <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
