From patchwork Tue May 12 10:12:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 471217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 961F71400B7 for ; Tue, 12 May 2015 20:12:30 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 72B271A0145 for ; Tue, 12 May 2015 20:12:30 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3ED251A0035 for ; Tue, 12 May 2015 20:12:27 +1000 (AEST) Received: by ozlabs.org (Postfix, from userid 1023) id 21BBC1400B7; Tue, 12 May 2015 20:12:27 +1000 (AEST) MIME-Version: 1.0 Message-Id: <1431425540.370174.650440170650.3.gpush@pablo> In-Reply-To: <1431425540.369385.198769938566.1.gpush@pablo> To: skiboot@lists.ozlabs.org From: Jeremy Kerr Date: Tue, 12 May 2015 18:12:20 +0800 Subject: [Skiboot] [PATCH 3/5 v3] core/test: simulate proper locking in run-mem_region test X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently, this test doesn't do locking during region changes or allocations. This change adds the appropriate locking. Signed-off-by: Jeremy Kerr --- core/test/run-mem_region.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/test/run-mem_region.c b/core/test/run-mem_region.c index b98fe71..d1cc3dd 100644 --- a/core/test/run-mem_region.c +++ b/core/test/run-mem_region.c @@ -64,17 +64,19 @@ struct dt_node *dt_root; void lock(struct lock *l) { + assert(!l->lock_val); l->lock_val++; } void unlock(struct lock *l) { + assert(l->lock_val); l->lock_val--; } -bool lock_held_by_me(struct lock *l __attribute__((unused))) +bool lock_held_by_me(struct lock *l) { - return true; + return l->lock_val; } #define TEST_HEAP_ORDER 12 @@ -98,6 +100,8 @@ int main(void) skiboot_heap.start = (unsigned long)test_heap; skiboot_heap.len = TEST_HEAP_SIZE; + lock(&skiboot_heap.free_list_lock); + /* Allocations of various sizes. */ for (i = 0; i < TEST_HEAP_ORDER; i++) { p = mem_alloc(&skiboot_heap, 1ULL << i, 1, "here"); @@ -216,6 +220,10 @@ int main(void) mem_free(&skiboot_heap, p, "freed"); assert(mem_check(&skiboot_heap)); + unlock(&skiboot_heap.free_list_lock); + + /* lock the regions list */ + lock(&mem_region_lock); /* Test splitting of a region. */ r = new_region("base", (unsigned long)test_heap, TEST_HEAP_SIZE, NULL, REGION_SKIBOOT_HEAP); @@ -247,8 +255,11 @@ int main(void) assert(i == 3); while ((r = list_pop(®ions, struct mem_region, list)) != NULL) { list_del(&r->list); + lock(&skiboot_heap.free_list_lock); mem_free(&skiboot_heap, r, __location__); + unlock(&skiboot_heap.free_list_lock); } + unlock(&mem_region_lock); assert(skiboot_heap.free_list_lock.lock_val == 0); __free(test_heap, ""); return 0;