Project

General

Profile

Feature #659

direct io unit test

Added by Sage Weil over 13 years ago. Updated about 13 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
% Done:

0%

Source:
Tags:
Backport:
Reviewed:
Affected Versions:
Pull request ID:

Description

For qa/workunits:

Test directio reads and writes where
- the file offset is 512-byte and not page aligned
- the buffer offset is 512-byte and not page aligned
and verify that the correct offset was read/written.

The test program should return a success or error code, and some useful output to identify which case(s) work or don't work.

The tcloud guys sent this, fwiw:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char *argv[]) {
        int i;
        int n = 0;
        void *buf = 0;
        int fd = open(argv[1], O_RDONLY | O_DIRECT);
        if (fd < 0) {
                printf("file open error %d\n", errno);
                return -1;
        }

        n = lseek(fd, 0, SEEK_END);
        printf("seek %d\n", n);
        n = lseek(fd, 0, SEEK_CUR);
        printf("seek %d\n", n);
        n = lseek(fd, 6656, SEEK_SET);
        printf("seek %d\n", n);

        n = posix_memalign(&buf, 512, 8192);
        printf("posix_memalign ret %d buf %p\n", n, buf);
        memset(buf, 0, n);

        n = read(fd, buf, 8192);
        printf("read %d bytes (err %d)\n", n, errno);
        char* buf1 = (char*)buf;
        for (i = 0; i < n; ++i)
                printf("%c", buf1[i]);
        printf("\n");
        free(buf);
        close(fd);
        return 0;
}

History

#1 Updated by Colin McCabe about 13 years ago

  • Status changed from New to Resolved

Also available in: Atom PDF