~ubuntu-branches/debian/experimental/libeatmydata/experimental

« back to all changes in this revision

Viewing changes to eatmydatatest.c

  • Committer: Package Import Robot
  • Author(s): Mattia Rizzolo
  • Date: 2014-10-03 20:48:40 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141003204840-xyxqm6u7d2l72c3x
Tags: 82-1
* New upstream release (Closes: #700649).
  + fixes a issue with faketime (Closes: #747078).
* Add Multi-Arch support (Closes: #694314, LP: #1275932):
  + Upstream now has a basic multiarch support on its own, update packaging.
  + debian/control: split package to libeatmydata1 being Multi-Arch:same.
  + debian/rules: move shared library to /usr/lib/<triplet>/libeatmydata.
* debian/{bin,lib}: drop, included upstream.
* debian/control:
  + [19c31a7] Bump Standards-Version to 3.9.6. No changes required.
  + Bump debhelper version to 9.
  + Add autotools-dev and strace to Build-Depends.
  + [687e4b8] Add dpkg-dev to depends of eatmydata
  + [8083867] wrap-and sort maintenance.
  + [64b0f93] Add myself as uploader.
  + [e74b025] Add Breaks/Replaces relations to libeatmydata1.
  + [d46838e,512aabc] Update Vcs-* links to collab-maint.
* debian/copyright:
  + Update accordingly the new upstream release.
  + Update to the debian-copyright format 1.0.
  + Update the homepage to launchpad.net/libeatmydata.
  + Add myself to copyright owners.
* debian/compat: bump to 9.
* debian/rules:
  + use dh with autotools_dev addon.
  + [71e3563] remove the override_dh_makeshilibs.
* [db986b8] debian/libeatmydata1.lintian-overrides: add
  non-dev-pkg-with-shlib-symlink.
* debian/patches:
  + executable-not-elf-or-script.patch. add to fix omonim
    lintian warning.
  + [6eba479,bce9c1d] multiarch-issue: add to fix a issue with multiarch (a
    script refers to a fixed position, non multiarch-compatible).
  + bug-702711.patch: update headers. Thanks Petter for the NMU.
* [ad63684] debian/eatmydata.install:
  + Drop eatmydata.sh, now installed in libeatmydata1.
  + Change source to debian/tmp.
* debian/libmydata1.install: add, it installs all /usr/lib/* stuff.
* [9908ebb] debian/eatmydata.manpages: add to install the manpage.
* debian/watch, debian/upstream/signing-key.asc
  + [42f1561] add.
  + [86912da] fix debian-watch-may-check-gpg-signature lintian tag.
* debian/README.debian: drop, it's useless.

* Upload sponsored by Petter Reinholdtsen.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C): 2010, Modestas Vainius <modax@debian.org>
3
 
 
4
 
    This program is free software: you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation, either version 3 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
*/
17
 
#include <stdio.h>
18
 
#include <fcntl.h>
19
 
#include <errno.h>
20
 
#include <sys/mman.h>
21
 
#include <unistd.h>
22
 
#include <sys/stat.h>
23
 
 
24
 
int failed_tests = 0;
25
 
 
26
 
#define DATAFILENAME "eatmydatatest.dat"
27
 
#define TESTCASE(value, expected, desc) \
28
 
    { if (value != expected) { \
29
 
        fprintf(stderr, "Test case failed: %s (err=%d).\n", desc, value); \
30
 
        if (errno != 0) perror("-- System errno (if applicable)"); \
31
 
        failed_tests++; \
32
 
      } \
33
 
    }
34
 
 
35
 
// Returns true if file status flag was not filtered out.
36
 
int test_open_flag(int flag)
37
 
{
38
 
    int fd, res;
39
 
 
40
 
    res = -1;
41
 
    fd = open(DATAFILENAME, O_CREAT|O_TRUNC|O_WRONLY|flag, S_IRUSR|S_IWUSR);
42
 
    if (fd != -1) {
43
 
        res = fcntl(fd, F_GETFL);
44
 
    }
45
 
    if (res == -1) {
46
 
        res = errno;
47
 
        close(fd);
48
 
        unlink(DATAFILENAME);
49
 
        errno = res;
50
 
        return -1;
51
 
    }
52
 
    close(fd);
53
 
    unlink(DATAFILENAME);
54
 
    return res & flag;
55
 
}
56
 
 
57
 
int main(int argc, char** argv)
58
 
{
59
 
    int fd;
60
 
 
61
 
    TESTCASE(test_open_flag(O_SYNC), 0, "open(O_SYNC) flag was not filtered out");
62
 
    TESTCASE(test_open_flag(O_DSYNC), 0, "open(O_DSYNC) flag was not filtered out");
63
 
 
64
 
    // Open and close FD in order to make sure its invalid.
65
 
    fd = open(DATAFILENAME, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
66
 
    if (fd == -1)
67
 
        perror("unable to open " DATAFILENAME);
68
 
    if (close(fd) == -1)
69
 
        perror("unable to close " DATAFILENAME " file descriptor");
70
 
    unlink(DATAFILENAME);
71
 
 
72
 
    // Now test fsync and friends by feeding them an invalid file descriptor.
73
 
    // System implementation should fail with EBADF while libeatmydata
74
 
    // implementation will succeed.
75
 
    TESTCASE(fsync(fd), 0, "system fsync() was not overridden");
76
 
    TESTCASE(fdatasync(fd), 0, "system fdatasync() was not overriden");
77
 
    TESTCASE(msync(0, 1, 1), 0, "system msync() was not overriden");
78
 
 
79
 
    if (failed_tests > 0) {
80
 
        fprintf(stderr, "%d test cases failed\n", failed_tests);
81
 
        return 2;
82
 
    }
83
 
 
84
 
    return 0;
85
 
}