reuse the code from test_lib