Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753717AbcCIPbW (ORCPT ); Wed, 9 Mar 2016 10:31:22 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:59386 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933093AbcCIPbM (ORCPT ); Wed, 9 Mar 2016 10:31:12 -0500 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= To: Shuah Khan Cc: devel@driverdev.osuosl.org, Gustavo Padovan , Riley Andrews , Daniel Vetter , John Harrison , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Greg Hackmann , Rob Clark , linux-kselftest@vger.kernel.org, Maarten Lankhorst , Daniel Stone , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , =?UTF-8?q?Emilio=20L=C3=B3pez?= Subject: [RFC PATCH v1 5/9] selftest: sync: destruction tests for sw_sync framework Date: Wed, 9 Mar 2016 12:28:58 -0300 Message-Id: <1457537342-678-6-git-send-email-emilio.lopez@collabora.co.uk> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457537342-678-1-git-send-email-emilio.lopez@collabora.co.uk> References: <1457537342-678-1-git-send-email-emilio.lopez@collabora.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4973 Lines: 147 These tests are based on the libsync test suite from Android. This commit includes tests for operations on destructed objects. Signed-off-by: Emilio López --- tools/testing/selftests/sync/Makefile | 1 + tools/testing/selftests/sync/sync_destroyed.c | 90 +++++++++++++++++++++++++++ tools/testing/selftests/sync/sync_test.c | 1 + tools/testing/selftests/sync/synctest.h | 3 + 4 files changed, 95 insertions(+) create mode 100644 tools/testing/selftests/sync/sync_destroyed.c diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile index 9944957..4104d22 100644 --- a/tools/testing/selftests/sync/Makefile +++ b/tools/testing/selftests/sync/Makefile @@ -15,6 +15,7 @@ TESTS += sync_alloc.o TESTS += sync_fence.o TESTS += sync_merge.o TESTS += sync_wait.o +TESTS += sync_destroyed.o sync_test: $(SRC) $(TESTS) diff --git a/tools/testing/selftests/sync/sync_destroyed.c b/tools/testing/selftests/sync/sync_destroyed.c new file mode 100644 index 0000000..4d42f0e --- /dev/null +++ b/tools/testing/selftests/sync/sync_destroyed.c @@ -0,0 +1,90 @@ +/* + * sync fence tests on destroyed timelines + * Copyright 2015-2016 Collabora Ltd. + * + * Based on the implementation from the Android Open Source Project, + * + * Copyright 2012 Google, Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include "sync.h" +#include "sw_sync.h" +#include "synctest.h" + +struct fds_test { + int timeline; + int fencesig, fencekill; + int result; +}; + +static int test_fence_wait_on_destroyed_timeline_thread(void *d) +{ + struct fds_test *data = d; + int ret; + + /* in case of errors */ + data->result = 1; + + ret = sw_sync_timeline_inc(data->timeline, 100); + ASSERT(ret == 0, "Failure advancing timeline\n"); + + ret = sync_wait(data->fencekill, -1); + ASSERT(ret == -1, "Failure waiting on fence\n"); + + /* no errors occurred */ + data->result = 0; + return 0; +} + +int test_fence_wait_on_destroyed_timeline(void) +{ + struct fds_test data; + pthread_t thread; + int valid; + + data.timeline = sw_sync_timeline_create(); + valid = sw_sync_timeline_is_valid(data.timeline); + ASSERT(valid, "Failure allocating timeline\n"); + + data.fencesig = sw_sync_fence_create(data.timeline, "allocFence", 100); + data.fencekill = sw_sync_fence_create(data.timeline, "allocFence", 200); + + /* Spawn a thread to wait on a fence when the timeline is killed */ + pthread_create(&thread, NULL, (void *(*)(void *)) + test_fence_wait_on_destroyed_timeline_thread, &data); + + /* Wait for the thread to spool up */ + sync_wait(data.fencesig, -1); + + /* Kill the timeline */ + sw_sync_timeline_destroy(data.timeline); + + /* wait for the thread to clean up */ + pthread_join(thread, NULL); + + sw_sync_fence_destroy(data.fencesig); + sw_sync_fence_destroy(data.fencekill); + + return data.result; +} diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c index 344a2f6..91f6b51 100644 --- a/tools/testing/selftests/sync/sync_test.c +++ b/tools/testing/selftests/sync/sync_test.c @@ -66,6 +66,7 @@ int main(void) err += RUN_TEST(test_fence_one_timeline_merge); err += RUN_TEST(test_fence_merge_same_fence); err += RUN_TEST(test_fence_multi_timeline_wait); + err += RUN_TEST(test_fence_wait_on_destroyed_timeline); if (err) printf("[FAIL]\tsync errors: %d\n", err); diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h index 9287393..bc8faae0 100644 --- a/tools/testing/selftests/sync/synctest.h +++ b/tools/testing/selftests/sync/synctest.h @@ -54,4 +54,7 @@ int test_fence_merge_same_fence(void); /* Fence wait tests */ int test_fence_multi_timeline_wait(void); +/* Fence test on destroyed timelines */ +int test_fence_wait_on_destroyed_timeline(void); + #endif -- 2.5.0