LoginSignup
3
3

More than 5 years have passed since last update.

westonモジュールのテスト

Posted at

参考
http://wayland.freedesktop.org/testing.html

westonそのものや、westonモジュールをテストする方法。

Makefile.amの書き方

tests/Makefile.amのmodule_testsにhoge-test.laのような名前でテストを追加する。
末尾の拡張子は重要でこれを見てweston-tests-envでテストの実行方法が決定される。

hoge-test.laのビルドオプションについては他のCompositorTestsと同様に書けばよい。

Makefile.am

#(省略)

module_tests =                          \
        surface-test.la                 \
        surface-global-test.la          \
        hoge-test.la # 追加

#(省略)

hoge_test_la_SOURCES = hoge-test.c
hoge_test_la_LDFLAGS = -module -avoid-version -rpath $(libdir)

#(省略)

テストコードの書き方

参考URLから引用

static void
test_foo(void *data)
{
    struct weston_compositor *compositor = data;

    /* Test stuff...
    assert(...);
    assert(...);
    ...
    */

    wl_display_terminate(compositor->wl_display);
}

WL_EXPORT int
module_init(struct weston_compositor *compositor,
            int *argc, char *argv[], const char *config_file)
{
    struct wl_event_loop *loop;

    loop = wl_display_get_event_loop(compositor->wl_display);

    wl_event_loop_add_idle(loop, test_foo, compositor);

    return 0;
}

基本的な部分はモジュールを作るときのコードと同じ。
テストはassertでおこなう。

テスト用wl_resourceの作り方

ちょっと細かい話。テストのためにwl_resourceが必要になったとき、わざわざクライアントプロセスをフォークさせなくても以下の方法でwl_resourceを作ることができる。


struct wl_client* dummy_client=NULL;
int sockets[2];
struct wl_resource* resource=NULL;

assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sockets) == 0);
dummy_client = wl_client_create(compositor->wl_display, sockets[0]);
assert(dummy_client);

resource = wl_resource_create(dummy_client,&wl_display_interface, 4, 0);
assert(resource);

テストの実行

ソースディレクトリ直下で

$ make check

ログはtests/test-suite.log, tests/logsにでる。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3