From 29348b80a6120dd1480ccabaf9e2f5186a2ec0a2 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Thu, 17 Apr 2014 14:03:14 +0200 Subject: [PATCH] Rewrite files_compare function Refactoring files_compare function now, when backtrack functionality is available. Change-Id: I5bde968289a3dea7b4c6aff2d9b075b5c22953de --- tests/libsmack-tests/test_cases.cpp | 40 ++++++++++++------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/tests/libsmack-tests/test_cases.cpp b/tests/libsmack-tests/test_cases.cpp index c9d8f96..e2fac42 100644 --- a/tests/libsmack-tests/test_cases.cpp +++ b/tests/libsmack-tests/test_cases.cpp @@ -18,8 +18,9 @@ * @file test_cases.cpp * @author Pawel Polawski (p.polawski@samsung.com) * @author Jan Olszak (j.olszak@samsung.com) + * @author Zofia Abramowska (z.abramowska@samsung.com) * @version 1.0 - * @brief libprivilege test runer + * @brief libsmack test runner */ #include @@ -51,12 +52,8 @@ const std::vector accessesBasic = { "r", "w", "x", "wx", "rx", "rw" //This one define is required for sockaddr_un initialization #define SOCK_PATH "/tmp/test-smack-socket" - - int files_compare(int fd1, int fd2) { - int result = 0; - //for getting files sizes struct stat fs1, fs2; @@ -65,36 +62,25 @@ int files_compare(int fd1, int fd2) void *h2 = MAP_FAILED; //getting files information - if (fstat(fd1, &fs1) == -1) { - perror("fstat"); - return -1; - } - if (fstat(fd2, &fs2) == -1) { - perror("fstat"); - return -1; - } + RUNNER_ASSERT_MSG_BT(fstat(fd1, &fs1) == 0, "fstat failed: " << strerror(errno)); + RUNNER_ASSERT_MSG_BT(fstat(fd2, &fs2) == 0, "fstat failed: " << strerror(errno)); if (fs1.st_size != fs2.st_size) //if files are identical size will be the same return -1; //mapping files to process memory - if ((h1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd1, 0 )) == MAP_FAILED) { - result = -1; - goto end; - } + RUNNER_ASSERT_MSG_BT((h1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd1, 0 )) != MAP_FAILED, + "mmap failed for fd=" << fd1 << " : " << strerror(errno)); + if ((h2 = mmap(0, fs2.st_size, PROT_READ, MAP_SHARED, fd2, 0 )) == MAP_FAILED) { - result = -1; - goto end; + munmap(h1, fs1.st_size); + RUNNER_ASSERT_MSG_BT(h2 != MAP_FAILED, "mmap failed for fd=" << fd2 + << " : " << strerror(errno)); } - result = memcmp(h1, h2, fs1.st_size); - - //cleaning after mmap() -end: - if (h2 != MAP_FAILED) - munmap(h2, fs2.st_size); - if (h1 != MAP_FAILED) - munmap(h1, fs1.st_size); + int result = memcmp(h1, h2, fs1.st_size); + munmap(h1, fs1.st_size); + munmap(h2, fs2.st_size); return result; } -- 2.7.4