[rhel6-branch 01/10] Add test script for mknod-stub

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Related: rhbz#706099
---
 command-stubs/mknod-test |   86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)
 create mode 100644 command-stubs/mknod-test

diff --git a/command-stubs/mknod-test b/command-stubs/mknod-test
new file mode 100644
index 0000000..abff629
--- /dev/null
+++ b/command-stubs/mknod-test
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+#
+# mknod-test
+#
+# Copyright (C) 2011  Red Hat, Inc.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+from subprocess import call, check_call, CalledProcessError
+import sys
+
+
+def create_device_test(device, type, major, minor):
+    # new device
+    rc = call(['mknod', device, type, major, minor])
+    if not rc == 0:
+        print('mknod: create new device test failed')
+        sys.exit(1)
+
+    try:
+        os.stat(device)
+    except OSError:
+        print('mknod: create new device test failed')
+        sys.exit(1)
+
+    # existing device
+    fail = False
+    rc = call(['mknod', device, type, major, minor])
+    if rc == 0:
+        print('mknod: create existing device test failed')
+        fail = True
+
+    # cleanup
+    os.unlink(device)
+
+    if fail:
+        sys.exit(1)
+
+def wrong_device_type_test():
+    rc = call(['mknod', '/dev/test-wrong', 'x', '1', '1'])
+    if rc == 0:
+        print('mknod: wrong device type test failed')
+        sys.exit(1)
+
+def wrong_usage_test():
+    try:
+        # missing all arguments
+        check_call(['mknod'])
+        # missing major, minor
+        check_call(['mknod', '/dev/test-wrong', 'b'])
+        check_call(['mknod', '/dev/test-wrong', 'c'])
+        # extra arguments
+        check_call(['mknod', '/dev/test', 'c', '1', '1', 'extra'])
+    except CalledProcessError:
+        # this is OK
+        pass
+    else:
+        print('mknod: wrong usage test failed')
+        sys.exit(1)
+
+def help_test():
+    rc = call(['mknod', '--help'])
+    if not rc == 0:
+        print('mknod: help test failed')
+        sys.exit(1)
+
+
+if __name__ == '__main__':
+    create_device_test('/dev/test-block', 'b', '1', '1')
+    create_device_test('/dev/test-char', 'c', '1', '1')
+    wrong_device_type_test()
+    wrong_usage_test()
+    help_test()
-- 
1.7.3.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux