From patchwork Tue Feb 6 22:58:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balint Reczey X-Patchwork-Id: 870613 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CpQqC8Wf"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OgxAb9t6"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zcBNW0n40z9s1h for ; Thu, 8 Feb 2018 06:34:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Date:From:Message-ID: Reply-To:To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=VpE6VSpjGGZNQaf24TnaVTMrwsQB5cGSVqoTsWFUJDk=; b=CpQqC8Wf/hUdFD 9nPGof+1zSrIJDpLb+29LOka8EM1V88aiPpnSozm+0ebu5WmKlBxZuL6CtWmPHAZNBR6f0fYhkS+r hZv1F3/i5sSFH4G8+GFCEDnk2fZBO+fvh8prnJaVOEqBHS5LpicgnO2Jo9jtqtEHnggu0hN5c0d/f I+1A2YVfGSNHfJPBUIauuSLoX+6eFrap5MXy6iAMw1hG0IAnVUzqi0ni/Pr5kakIj24wIQGn6H+Lu fmsR5lsIFh/sYF0ooQfcDMsC77YOLmVU/jqGKoLtnf+96P7I8dxbP9Ws0rWCjiFlVeQ9cBR4R5jHp FnzPQxyAzKZkCd7g2Ipg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ejVUG-0003ld-17; Wed, 07 Feb 2018 19:34:32 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ejVUC-0003iy-LA for linux-mtd@lists.infradead.org; Wed, 07 Feb 2018 19:34:30 +0000 Received: by mail-pf0-x243.google.com with SMTP id p1so760939pfh.4 for ; Wed, 07 Feb 2018 11:34:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:sender:from:date:subject; bh=lbdp8RP6YDtdSR0IznMd3U1Bl7wbg/1eIlO+BW3UnTQ=; b=OgxAb9t6o/6EK8RiBOLxWrO0ZRwdQBZLekAs36Wuee7V/wz05kEdA4BIQkG6WHIJgY MSheF9iAmavcRxXQ4YS9F9tScdzShxkvMb1L+T5mRovQZlvphL/S+RXxV3PxJG0hTZEA jEVUFHbaA9ZHI+rdVRyRC9zBuPUVtl9kYv2Xua/2yNBV69P+ssdyPRnEGdCr9JVHDp5Z yhAkKRiVGK8KzpwdJdLsp58dcoztbXsYKN4vPyGuFxyaCeLFXiyFgmEzUcCnWYA0fral AmvZ/h+p5iaL5D6RbR9LZgqti90RYKJhmnLEx5dvxN5qi8YrTQivUYOY5HAP4Cv4qdjM Oxtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:sender:from:date:subject; bh=lbdp8RP6YDtdSR0IznMd3U1Bl7wbg/1eIlO+BW3UnTQ=; b=ECLkScdZKOwPRlI6RuHmGcTIq2f97apbQRYzm4iL71Hd/dO/bOtxxvrVFnr+i5eDDb 1SqqLIDQjzUIBYz9+X7BlonTA8PdqregNJ70HskfEZ41zentne+1oibFYYn9CQqTACiz aopnk1tSkgXHOBsOVmckm8Ph4T9HJV1+/7A6LNcgtktG7lMw7YwVMtGhZgmm21VN0r7/ OPsmxGCv/ZZUSTgRSZAThJZjcsThp0ZFFj/FQ1mGBIriRmq4AOEDBnb9DEJuEU23v47g kGJkhZ1qDNAZD4KIxcopfLKSvYXqGpnR2HPCPSV+HN9UmtY1nunOML7I8v3GTwJi9Oxa +/tw== X-Gm-Message-State: APf1xPACz4ssU5j8qlUKHNdtBt8kFnQo1bleDo7zg9Xp/6X1cye4Ds/w Zro/NkxUat/ch/3E49HHEjy9CQ== X-Google-Smtp-Source: AH8x224/bZ5FPzPBJtEimcshqFD1MTV8+9RcSxSYfXekKmXVp3QxqVPF4gipRouEYQWXGxLJVGNjdQ== X-Received: by 10.99.110.205 with SMTP id j196mr5718323pgc.54.1518032057394; Wed, 07 Feb 2018 11:34:17 -0800 (PST) Received: from localhost ([223.27.245.122]) by smtp.gmail.com with ESMTPSA id b69sm5405682pfk.128.2018.02.07.11.34.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Feb 2018 11:34:16 -0800 (PST) Message-ID: <5a7b54b8.c83c620a.2d3df.7f47@mx.google.com> From: Balint Reczey X-Google-Original-From: Balint Reczey Date: Wed, 7 Feb 2018 05:58:21 +0700 Subject: [PATCH 2/2] mtd: unittests: Decode arg size from ioctl request X-Spam-Note: CRM114 invocation failed X-Spam-Score: 0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c00:0:0:0:243 listed in] [list.dnswl.org] 1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date -0.0 SPF_PASS SPF: sender matches SPF record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 1.0 MISSING_HEADERS Missing To: header 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (rbalint[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Balint Reczey --- tests/unittests/libmtd_test.c | 30 +++++++++++++++--------------- tests/unittests/libubi_test.c | 22 +++++++++++----------- tests/unittests/test_lib.h | 11 ++++------- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/tests/unittests/libmtd_test.c b/tests/unittests/libmtd_test.c index fc28dc0..f36fb56 100644 --- a/tests/unittests/libmtd_test.c +++ b/tests/unittests/libmtd_test.c @@ -70,7 +70,7 @@ static void test_mtd_mark_bad(void **state) mtd.eb_cnt = 1024; mtd.eb_size = 128; seek = (loff_t)eb * mtd.eb_size; - expect_ioctl(MEMSETBADBLOCK, 0, &seek, sizeof(seek)); + expect_ioctl(MEMSETBADBLOCK, 0, &seek); int r = mtd_mark_bad(&mtd, 4, eb); assert_int_equal(r, 0); @@ -87,7 +87,7 @@ static void test_mtd_is_bad(void **state) mtd.eb_cnt = 1024; mtd.eb_size = 128; seek = (loff_t)eb * mtd.eb_size; - expect_ioctl(MEMGETBADBLOCK, 0, &seek, sizeof(seek)); + expect_ioctl(MEMGETBADBLOCK, 0, &seek); int r = mtd_is_bad(&mtd, 4, eb); assert_int_equal(r, 0); @@ -106,7 +106,7 @@ static void test_mtd_lock(void **state) memset(&ei, 0, sizeof(ei)); ei.start = eb * mtd.eb_size; ei.length = mtd.eb_size; - expect_ioctl(MEMLOCK, 0, &ei, sizeof(ei)); + expect_ioctl(MEMLOCK, 0, &ei); int r = mtd_lock(&mtd, 4, eb); assert_int_equal(r, 0); @@ -125,7 +125,7 @@ static void test_mtd_unlock(void **state) memset(&ei, 0, sizeof(ei)); ei.start = eb * mtd.eb_size; ei.length = mtd.eb_size; - expect_ioctl(MEMUNLOCK, 0, &ei, sizeof(ei)); + expect_ioctl(MEMUNLOCK, 0, &ei); int r = mtd_unlock(&mtd, 4, eb); assert_int_equal(r, 0); @@ -144,7 +144,7 @@ static void test_mtd_is_locked(void **state) memset(&ei, 0, sizeof(ei)); ei.start = eb * mtd.eb_size; ei.length = mtd.eb_size; - expect_ioctl(MEMISLOCKED, 0, &ei, sizeof(ei)); + expect_ioctl(MEMISLOCKED, 0, &ei); int r = mtd_is_locked(&mtd, 4, eb); assert_int_equal(r, 0); @@ -160,7 +160,7 @@ static void test_mtd_regioninfo(void **state) int mock_fd = 4; int regidx = 0xAA; rr.regionindex = regidx; - expect_ioctl(MEMGETREGIONINFO, 0, &rr, sizeof(rr)); + expect_ioctl(MEMGETREGIONINFO, 0, &rr); int r = mtd_regioninfo(mock_fd, regidx, &req); assert_int_equal(r, 0); @@ -187,12 +187,12 @@ static void test_mtd_erase_multi(void **state) ei.length = ei64.length; /* non offs64 first */ lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED; - expect_ioctl(MEMERASE, 0, &ei, sizeof(ei)); + expect_ioctl(MEMERASE, 0, &ei); int r = mtd_erase_multi(lib, &mtd, 4, eb, blocks); assert_int_equal(r, 0); lib->offs64_ioctls = OFFS64_IOCTLS_SUPPORTED; - expect_ioctl(MEMERASE64, 0, &ei64, sizeof(ei64)); + expect_ioctl(MEMERASE64, 0, &ei64); r = mtd_erase_multi(lib, &mtd, 4, eb, blocks); assert_int_equal(r, 0); @@ -224,12 +224,12 @@ static void test_mtd_erase(void **state) ei.length = ei64.length; /* non offs64 first */ lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED; - expect_ioctl(MEMERASE, 0, &ei, sizeof(ei)); + expect_ioctl(MEMERASE, 0, &ei); int r = mtd_erase(lib, &mtd, 4, eb); assert_int_equal(r, 0); lib->offs64_ioctls = OFFS64_IOCTLS_SUPPORTED; - expect_ioctl(MEMERASE64, 0, &ei64, sizeof(ei64)); + expect_ioctl(MEMERASE64, 0, &ei64); r = mtd_erase(lib, &mtd, 4, eb); assert_int_equal(r, 0); @@ -314,7 +314,7 @@ static void test_mtd_write_withoob(void **state) req.usr_data = (uint64_t)(unsigned long)buf; req.usr_oob = (uint64_t)(unsigned long)oob_data; req.mode = mode; - expect_ioctl(MEMWRITE, 0, &req, sizeof(req)); + expect_ioctl(MEMWRITE, 0, &req); int r = mtd_write(lib, &mtd, mock_fd, eb, offs, buf, len, oob_data, oob_len, mode); assert_int_equal(r, 0); @@ -348,12 +348,12 @@ static void test_mtd_read_oob(void **state) oob.ptr = buf; lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED; - expect_ioctl(MEMREADOOB, 0, &oob, sizeof(oob)); + expect_ioctl(MEMREADOOB, 0, &oob); int r = mtd_read_oob(lib, &mtd, mock_fd, start, length, buf); assert_int_equal(r, 0); lib->offs64_ioctls = OFFS64_IOCTLS_SUPPORTED; - expect_ioctl(MEMREADOOB64, 0, &oob64, sizeof(oob64)); + expect_ioctl(MEMREADOOB64, 0, &oob64); r = mtd_read_oob(lib, &mtd, mock_fd, start, length, buf); assert_int_equal(r, 0); @@ -388,12 +388,12 @@ static void test_mtd_write_oob(void **state) oob.ptr = buf; lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED; - expect_ioctl(MEMWRITEOOB, 0, &oob, sizeof(oob)); + expect_ioctl(MEMWRITEOOB, 0, &oob); int r = mtd_write_oob(lib, &mtd, mock_fd, start, length, buf); assert_int_equal(r, 0); lib->offs64_ioctls = OFFS64_IOCTLS_SUPPORTED; - expect_ioctl(MEMWRITEOOB64, 0, &oob64, sizeof(oob64)); + expect_ioctl(MEMWRITEOOB64, 0, &oob64); r = mtd_write_oob(lib, &mtd, mock_fd, start, length, buf); assert_int_equal(r, 0); diff --git a/tests/unittests/libubi_test.c b/tests/unittests/libubi_test.c index 3e08e42..8deae91 100644 --- a/tests/unittests/libubi_test.c +++ b/tests/unittests/libubi_test.c @@ -54,7 +54,7 @@ static void test_ubi_leb_unmap(void **state) { int mock_fd = 1; int lnum = 12; - expect_ioctl(UBI_IOCEBUNMAP, 0, &lnum, sizeof(lnum)); + expect_ioctl(UBI_IOCEBUNMAP, 0, &lnum); int r = ubi_leb_unmap(mock_fd, lnum); assert_int_equal(r, 0); @@ -65,7 +65,7 @@ static void test_ubi_is_mapped(void **state) { int mock_fd = 1; int lnum = 1; - expect_ioctl(UBI_IOCEBISMAP, 0, &lnum, sizeof(lnum)); + expect_ioctl(UBI_IOCEBISMAP, 0, &lnum); int r = ubi_is_mapped(mock_fd, lnum); assert_int_equal(r, 0); @@ -77,7 +77,7 @@ static void test_ubi_update_start(void **state) int mock_fd = 1; long long bytes = 0x1234; - expect_ioctl(UBI_IOCVOLUP, 0, &bytes, sizeof(bytes)); + expect_ioctl(UBI_IOCVOLUP, 0, &bytes); int r = ubi_update_start(NULL, mock_fd, bytes); assert_int_equal(r, 0); (void) state; @@ -116,7 +116,7 @@ static void test_ubi_rsvol(void **state) req.bytes = bytes; req.vol_id = vol_id; expect_open(node, O_RDONLY, 4); - expect_ioctl(UBI_IOCRSVOL, 0, &req, sizeof(req)); + expect_ioctl(UBI_IOCRSVOL, 0, &req); expect_close(4, 0); int r = ubi_rsvol(NULL, node, vol_id, bytes); assert_int_equal(r, 0); @@ -131,7 +131,7 @@ static void test_ubi_rnvols(void **state) struct ubi_rnvol_req req; memset(&req, 0xaf, sizeof(req)); expect_open(node, O_RDONLY, 4); - expect_ioctl(UBI_IOCRNVOL, 0, &req, sizeof(req)); + expect_ioctl(UBI_IOCRNVOL, 0, &req); expect_close(4, 0); int r = ubi_rnvols(lib, node, &req); assert_int_equal(r, 0); @@ -146,7 +146,7 @@ static void test_ubi_rmvol(void **state) const char *node = "/foo"; int vol_id = 12; expect_open(node, O_RDONLY, 4); - expect_ioctl(UBI_IOCRMVOL, 0, &vol_id, sizeof(vol_id)); + expect_ioctl(UBI_IOCRMVOL, 0, &vol_id); expect_close(4, 0); int r = ubi_rmvol(lib, node, vol_id); assert_int_equal(r, 0); @@ -166,7 +166,7 @@ static void test_ubi_leb_change_start(void **state) req.lnum = lnum; req.bytes = bytes; req.dtype = 3; - expect_ioctl(UBI_IOCEBCH, 0, &req, sizeof(req)); + expect_ioctl(UBI_IOCEBCH, 0, &req); int r = ubi_leb_change_start(lib, mock_fd, lnum, bytes); assert_int_equal(r, 0); @@ -209,7 +209,7 @@ static void test_ubi_mkvol(void **state) rr.name_len = strlen(vol_name); strncpy(rr.name, vol_name, UBI_MAX_VOLUME_NAME + 1); expect_open(node, O_RDONLY, 3); - expect_ioctl(UBI_IOCMKVOL, 0, &rr, sizeof(rr)); + expect_ioctl(UBI_IOCMKVOL, 0, &rr); expect_close(3,0); int r = ubi_mkvol(lib, node, &req); assert_int_equal(r, 0); @@ -225,7 +225,7 @@ void test_ubi_remove_dev(void **state) libubi_t lib = mock_libubi_open(); int ubi_dev = 0xAA; expect_open(node, O_RDONLY, 4); - expect_ioctl(UBI_IOCDET, 0, &ubi_dev, sizeof(ubi_dev)); + expect_ioctl(UBI_IOCDET, 0, &ubi_dev); expect_close(4,0); int r = ubi_remove_dev(lib, node, ubi_dev); assert_int_equal(r, 0); @@ -247,7 +247,7 @@ void test_ubi_attach(void **state) rr.ubi_num = 1; rr.mtd_num = 1; expect_open(node, O_RDONLY, 4); - expect_ioctl(UBI_IOCATT, 0, &rr, sizeof(rr)); + expect_ioctl(UBI_IOCATT, 0, &rr); expect_close(4,0); int r = ubi_attach(lib, node, &req); @@ -266,7 +266,7 @@ void test_ubi_set_property(void **state) memset(&req, 0, sizeof(req)); req.property = prop; req.value = val; - expect_ioctl(UBI_IOCSETVOLPROP, 0, &req, sizeof(req)); + expect_ioctl(UBI_IOCSETVOLPROP, 0, &req); int r = ubi_set_property(mock_fd, prop, val); assert_int_equal(r,0); diff --git a/tests/unittests/test_lib.h b/tests/unittests/test_lib.h index f5f0f34..806a4bc 100644 --- a/tests/unittests/test_lib.h +++ b/tests/unittests/test_lib.h @@ -45,16 +45,15 @@ int __wrap_ioctl(int fd, unsigned long req, ...) assert_true(fd > 0); check_expected(req); int retval = mock_type(int); - void *expected_arg = mock_type(void*); - size_t expected_len = mock_type(size_t); + char *expected_arg = mock_type(char*); if (expected_arg == NULL) return retval; va_list ap; va_start(ap, req); - void *arg = va_arg(ap, void *); + char *arg = va_arg(ap, char *); va_end(ap); assert_non_null(arg); - assert_memory_equal(expected_arg, arg, expected_len); + assert_memory_equal(expected_arg, arg, _IOC_SIZE(req)); return retval; } @@ -107,18 +106,16 @@ off_t __wrap_lseek(int fd, off_t seek, int whence) will_return(__wrap_close, Y);\ } while(0); -#define expect_ioctl(W,X,Y,Z) do { \ +#define expect_ioctl(W,X,Y) do { \ expect_value(__wrap_ioctl, req, W);\ will_return(__wrap_ioctl, X);\ will_return(__wrap_ioctl, Y);\ - will_return(__wrap_ioctl, Z);\ } while(0); #define expect_ioctl_short(X,Y) do { \ expect_value(__wrap_ioctl, req, X);\ will_return(__wrap_ioctl, Y);\ will_return(__wrap_ioctl, NULL);\ - will_return(__wrap_ioctl, 0);\ } while(0); #define expect_stat(X,Y) do { \