* @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 <string>
//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;
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;
}