3
# Check the flood control under dnotify
4
# Scenario: the main thread watch a file, a second thread is created
5
# writing 10 times a sec to that file, then after 5 seconds it stops
6
# and stops modifying the file for 6 seconds.
7
# the kernel monitoring should be stopped within one second in the
8
# first phase and then reactivated after a few seconds in the second
27
def wait_ms(ms = 100):
32
def resource_update_thread(filename):
37
# print "%s active" % (filename)
38
f = open(filename, "w")
45
# print "%s quiet" % (filename)
56
db_expect = [ 51, 54, 55, 52 ]
57
expect = [gamin.GAMExists, gamin.GAMEndExist]
59
def debug(path, type, data):
60
global dbg, db_expect, ok
62
# print "Got debug %s, %s, %s" % (path, type, data)
63
if path[-8:] != "temp_dir":
64
print "Error got debug path unexpected %s" % (path)
66
if db_expect[dbg] != type:
67
print "Error got debug event %d expected %d" % (type, db_expect[dbg])
71
def callback(path, event, which):
72
global top, expect, ok
73
print "Got callback: %s, %s" % (path, event)
74
if event == gamin.GAMAcknowledge:
77
if expect[top] != event:
78
print "Error got event %d expected %d" % (event, expect[top])
80
elif event != gamin.GAMChanged:
81
print "Error got event %d expected %d" % (event, gamin.GAMChanged)
85
shutil.rmtree ("temp_dir", True)
87
f = open("temp_dir/a", "w").close()
88
thread.start_new_thread(resource_update_thread, ("temp_dir/a",))
90
mon = gamin.WatchMonitor()
91
mon._debug_object("notify", debug, 0)
92
mon.watch_file("temp_dir/a", callback, 0)
94
# wait until the thread finishes, collecting events
100
#print "all threads terminated, exiting ..."
102
mon.stop_watch("temp_dir/a")
107
shutil.rmtree ("temp_dir", True)
110
print "Error: monitor got only %d events" % (top)
112
print "Error: event flow didn't worked properly, gor %d events" % (top)
113
elif dbg != 4 and gamin.has_debug_api == 1:
114
print "Error: debug got %d events insteads of 4" % (dbg)