Add basic test
This commit is contained in:
parent
eae100a669
commit
2c6af5856b
3 changed files with 119 additions and 0 deletions
20
Sanity/basic/main.fmf
Normal file
20
Sanity/basic/main.fmf
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
summary: Basic test
|
||||
description: Tests basic functionality of lockdev
|
||||
contact: František Hrdina <fhrdina@redhat.com>
|
||||
component:
|
||||
- lockdev
|
||||
test: ./test.sh
|
||||
framework: beakerlib
|
||||
recommend:
|
||||
- lockdev
|
||||
- gcc
|
||||
- lockdev-devel
|
||||
duration: 5m
|
||||
enabled: true
|
||||
tag:
|
||||
- Tier1
|
||||
tier: '1'
|
||||
adjust:
|
||||
- enabled: false
|
||||
when: distro < rhel-7
|
||||
continue: false
|
||||
34
Sanity/basic/test.sh
Executable file
34
Sanity/basic/test.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
||||
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
||||
|
||||
rlJournalStart
|
||||
rlPhaseStartSetup
|
||||
rlAssertRpm lockdev
|
||||
|
||||
tmpDir=$(pwd)
|
||||
|
||||
rlIsRHEL && repos="--enablerepo=rhel-CRB --enablerepo=rhel-buildroot"
|
||||
rlIsCentOS && repos="--enablerepo=crb"
|
||||
rlIsRHELLike && rlRun "dnf install -y $(rlGetRecommended) $repos"
|
||||
rlCheckDependencies
|
||||
|
||||
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
|
||||
rlRun "pushd $tmp"
|
||||
rlRun "gcc -o test_lockdev $tmpDir/test_lockdev.c -llockdev"
|
||||
rlRun "chmod +x test_lockdev"
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest
|
||||
rlRun "./test_lockdev &> lockdev.log"
|
||||
rlAssertNotGrep "No tty device found tty" lockdev.log
|
||||
rlAssertGrep "Device in use" lockdev.log
|
||||
rlAssertGrep "Device is locked" lockdev.log
|
||||
rlAssertGrep "Device is unlocked" lockdev.log
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartCleanup
|
||||
rlRun "popd"
|
||||
rlRun "rm -r $tmp" 0 "Remove tmp directory"
|
||||
rlPhaseEnd
|
||||
rlJournalEnd
|
||||
65
Sanity/basic/test_lockdev.c
Normal file
65
Sanity/basic/test_lockdev.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <lockdev.h>
|
||||
|
||||
#define DEVICE_PATH "/dev/"
|
||||
|
||||
int main() {
|
||||
struct dirent *entry;
|
||||
DIR *dp;
|
||||
char device[256];
|
||||
int fd;
|
||||
|
||||
dp = opendir(DEVICE_PATH);
|
||||
if (dp == NULL) {
|
||||
perror("opendir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((entry = readdir(dp))) {
|
||||
if (strncmp(entry->d_name, "ttyS", 4) == 0) {
|
||||
snprintf(device, sizeof(device), "%s%s", DEVICE_PATH, entry->d_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
|
||||
if (entry == NULL) {
|
||||
fprintf(stderr, "No tty device found ttyS*\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Device in use: %s\n", device);
|
||||
|
||||
fd = open(device, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dev_lock(device) == -1) {
|
||||
perror("dev_lock");
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Device is locked.\n");
|
||||
|
||||
if (dev_unlock(device, 0) == -1) {
|
||||
perror("dev_unlock");
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Device is unlocked.\n");
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue