1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
|
#!/usr/bin/env python3
#===============================================================================
# Copyright 2013 NetApp, Inc. All Rights Reserved,
# contribution by Jorge Mora <mora@netapp.com>
#
# 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.
#===============================================================================
import os
import time
import errno
import signal
import struct
import traceback
from formatstr import *
import nfstest_config as c
from baseobj import BaseObj
from nfstest.test_util import TestUtil
import packet.nfs.nfs3_const as nfs3_const
import packet.nfs.nfs4_const as nfs4_const
import packet.nfs.nlm4_const as nlm4_const
from fcntl import fcntl,F_RDLCK,F_WRLCK,F_UNLCK,F_SETLK,F_SETLKW,F_GETLK
# Module constants
__author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL
__copyright__ = "Copyright (C) 2013 NetApp, Inc."
__license__ = "GPL v2"
__version__ = "1.3"
USAGE = """%prog --server <server> [--client <client>] [options]
Locking tests
=============
Basic locking tests verify that a lock is granted using various arguments
to fcntl. These include blocking and non-blocking locks, read or write locks,
where the file is opened either for reading, writing or both. It also checks
different ranges including limit conditions.
Non-overlapping tests verity that locks are granted on both the client under
test and a second process or a remote client when locking the same file.
Overlapping tests verity that a lock is granted on the client under test
and a second process or a remote client trying to lock the same file will
be denied if a non-blocking lock is issue or will be blocked if a blocking
lock is issue on the second process or remote client.
Examples:
Run the tests which use only the main client (no client option):
%prog --server 192.168.0.2 --export /exports
Use short options instead:
%prog -s 192.168.0.2 -e /exports
Use positional arguments with nfsversion=3 for extra client:
%prog -s 192.168.0.2 -e /exports --client 192.168.0.10:::3
Use named arguments instead:
%prog -s 192.168.0.2 -e /exports --client 192.168.0.10:nfsversion=3
Use positional arguments with nfsversion=3 for second process:
%prog -s 192.168.0.2 -e /exports --nfsopts :::3
Use named arguments instead:
%prog -s 192.168.0.2 -e /exports --nfsopts nfsversion=3
Notes:
The user id in the local host and the host specified by --client must
have access to run commands as root using the 'sudo' command without
the need for a password.
The user id must be able to 'ssh' to remote host without the need for
a password."""
# Test script ID
SCRIPT_ID = "LOCK"
# Basic tests
BTESTS = ['btest01']
# Non-overlapping lock tests using a second process
NPTESTS = [
'nptest01',
'nptest02',
'nptest03',
'nptest04',
]
# Non-overlapping lock tests using a second client
NCTESTS = [
'nctest01',
'nctest02',
'nctest03',
'nctest04',
]
# Overlapping lock tests using a second process
OPTESTS = [
'optest01',
'optest02',
'optest03',
'optest04',
'optest05',
'optest06',
'optest07',
'optest08',
'optest09',
]
# Overlapping lock tests using a second client
OCTESTS = [
'octest01',
'octest02',
'octest03',
'octest04',
'octest05',
'octest06',
'octest07',
'octest08',
'octest09',
]
# Dictionary having the number of processes required by each test
TEST_PROCESS_DICT = {x:1 for x in NPTESTS + OPTESTS}
TEST_PROCESS_DICT.update({x:2 for x in ["optest09"]})
# Dictionary having the number of clients required by each test
TEST_CLIENT_DICT = {x:1 for x in NCTESTS + OCTESTS}
TEST_CLIENT_DICT.update({x:2 for x in ["octest09"]})
# All tests, include the test groups in the list of test names
# so they are displayed in the help
TESTNAMES = BTESTS + ["noverlap", "nptest"] + NPTESTS + ["nctest"] + \
NCTESTS + ["overlap", "optest"] + OPTESTS + ["octest"] + OCTESTS
TESTGROUPS = {
"noverlap": {
"tests": NPTESTS + NCTESTS,
"desc": "Run all non-overlapping locking tests: ",
},
"nptest": {
"tests": NPTESTS,
"desc": "Run all non-overlapping locking tests using a second process: ",
},
"nctest": {
"tests": NCTESTS,
"desc": "Run all non-overlapping locking tests using a second client: ",
},
"overlap": {
"tests": OPTESTS + OCTESTS,
"desc": "Run all overlapping locking tests: ",
},
"optest": {
"tests": OPTESTS,
"desc": "Run all overlapping locking tests using a second process: ",
},
"octest": {
"tests": OCTESTS,
"desc": "Run all overlapping locking tests using a second client: ",
},
}
# Mapping dictionaries
LOCKMAP = {F_RDLCK:'F_RDLCK', F_WRLCK:'F_WRLCK', F_UNLCK:'F_UNLCK'}
LOCKMAP_R = {'read':F_RDLCK, 'write':F_WRLCK, 'unlock':F_UNLCK}
SLOCKMAP = {F_SETLK:'F_SETLK', F_SETLKW:'F_SETLKW'}
SLOCKMAP_R = {'immediate':F_SETLK, 'block':F_SETLKW}
OPENMAP = {os.O_RDONLY:'O_RDONLY', os.O_WRONLY:'O_WRONLY', os.O_RDWR:'O_RDWR'}
OPENMAP_R = {'read':os.O_RDONLY, 'write':os.O_WRONLY, 'rdwr':os.O_RDWR}
# Locking and helper functions
def getlock(fd, lock_type, offset=0, length=0, stype=F_SETLK, timeout=30):
"""Get byte range lock on file given by file descriptor"""
lockdata = struct.pack('hhllhh', lock_type, 0, offset, length, 0, 0)
if stype == F_SETLK:
out = fcntl(fd, stype, lockdata)
else:
# Set alarm so the blocking lock could be interrupted
signal.alarm(timeout)
try:
out = fcntl(fd, stype, lockdata)
finally:
# Reset alarm
signal.alarm(0)
return struct.unpack('hhllhh', out)
def testlock(fd, lock_type, offset=0, length=0):
"""Test byte range lock on file given by file descriptor"""
lockdata = struct.pack('hhllhh', lock_type, 0, offset, length, 0, 0)
out = fcntl(fd, F_GETLK, lockdata)
return struct.unpack('hhllhh', out)
def get_ioerror(ioerrno, err):
"""Return fail message when expecting an error"""
fmsg = ""
# Test expression to return
expr = ioerrno == err
if not ioerrno:
fmsg = ": no error was returned"
elif ioerrno != err:
# Got the wrong error
expected = errno.errorcode[err]
error = errno.errorcode[ioerrno]
fmsg = ": expecting %s, got %s" % (expected, error)
return (expr, fmsg)
def get_range(offset, length):
"""Return byte range (start, end) given by the offset and length"""
if length == 0:
# Lock until the end of file
end = 0xffffffffffffffff
else:
end = offset + length - 1
return (offset, end)
class ProcInfo(BaseObj):
"""ProcInfo object"""
# Class attributes:
# ProcInfo object could be used as a direct replacement for Rexec object
_fattrs = ("execobj",)
# ProcInfo local and remote ordinal number
_procidx = [2, 2]
def __init__(self, clientobj, execobj):
self.clientobj = clientobj # Host object associated with this process
self.execobj = execobj # Rexec object for this process
self.offset = 0 # Lock offset for this process
self.length = 0 # Lock length for this process
self.fd = None # File descriptor associated with this process
self.result = None # Output of locking operation
self.need_unlock = None # Lock was granted and it needs to be unlocked
self.isoverlap = None # Lock overlaps with main lock
# Ordinal number for this object
self.proc_ordnum = ordinal_number(self._procidx[self.remote])
# Increment local or remote ordinal number
self._procidx[self.remote] += 1
def close_fd(self):
"""Close opened file"""
if self.fd is not None:
self.run(os.close, self.fd)
self.fd = None
def reset(self):
"""Reset lock info"""
self.result = None
self.need_unlock = None
def lock_range(self, offset, length):
"""Set lock range and return this object"""
self.offset = offset
self.length = length
self.isoverlap = None
self.reset()
return self
# Main test object definition
class LockTest(TestUtil):
"""LockTest object
LockTest() -> New test object
Usage:
x = LockTest(testnames=['test1', ...])
# Run all the tests
x.run_tests()
x.exit()
"""
def __init__(self, **kwargs):
"""Constructor
Initialize object's private data.
"""
TestUtil.__init__(self, **kwargs)
self.opts.version = "%prog " + __version__
# Set default script options
# Display all test messages
self.opts.set_defaults(tverbose='2')
# Options specific for this test script
hmsg = "Remote NFS client and options used for conflicting lock tests. " \
"Clients are separated by a ',' and each client definition is " \
"a list of arguments separated by a ':' given in the following " \
"order if positional arguments is used (see examples): " \
"clientname:server:export:nfsversion:port:proto:sec:mtpoint"
self.test_opgroup.add_option("--client", default=None, help=hmsg)
hmsg = "Local process NFS options used for conflicting lock tests. " \
"Processes are separated by a ',' and each process definition " \
"is a list of arguments separated by a ':' given in the " \
"following order if positional arguments is used (see examples): " \
":server:export:nfsversion:port:proto:sec:mtpoint"
self.test_opgroup.add_option("--nfsopts", default=None, help=hmsg)
hmsg = "Offset of first lock granted [default: %default]"
self.test_opgroup.add_option("--offset", default="4k", help=hmsg)
hmsg = "Length of first lock granted [default: %default]"
self.test_opgroup.add_option("--length", default="4k", help=hmsg)
# Object attribute: self.unlock_delay
hmsg = "Time in seconds to unlock first lock [default: %default]"
self.test_opgroup.add_option("--unlock-delay", type="float", default=2.0, help=hmsg)
# Object attribute: self.lockw_timeout
hmsg = "Time in seconds to wait for blocked lock after " \
"conflicting lock has been released [default: %default]"
self.test_opgroup.add_option("--lockw-timeout", type="int", default=30, help=hmsg)
hmsg = "List of open types to test [default: %default]"
self.test_opgroup.add_option("--opentype", default="read,write,rdwr", help=hmsg)
hmsg = "List of lock types to test [default: %default]"
self.test_opgroup.add_option("--locktype", default="read,write", help=hmsg)
hmsg = "List of open types to test on remote client [default: %default]"
self.test_opgroup.add_option("--opentype2", default="read,write,rdwr", help=hmsg)
hmsg = "List of lock types to test on remote client [default: %default]"
self.test_opgroup.add_option("--locktype2", default="read,write", help=hmsg)
hmsg = "List of set lock types to test [default: %default]"
self.test_opgroup.add_option("--setlock", default="immediate,block", help=hmsg)
hmsg = "Create a packet trace for each sub-test. Use it with " + \
"caution since it will create a lot of packet traces. " + \
"Use --createtraces instead unless trying to get a packet " + \
"trace for a specific sub-test. Best if it is used in " + \
"combination with the --runtest option."
self.cap_opgroup.add_option("--subtraces", action="store_true", default=False, help=hmsg)
self.scan_options()
self.st_time = time.time()
# Convert units
self.offset = int_units(self.offset)
self.length = int_units(self.length)
if self.subtraces:
# Disable createtraces option since a packet trace will be created
# here for every sub-test when the --subtraces option is set and
# a packet trace should not be started by test_util.py
self.createtraces = False
# Sanity checks
if self.offset < 2:
self.opts.error("invalid value given in --offset [%d], must be > 1" % self.offset)
if self.length < 2:
self.opts.error("invalid value given in --length [%d], must be > 1" % self.length)
if float(self.lockw_timeout) < (1.2*self.unlock_delay):
self.opts.error("invalid value given in --lockw-timeout, must be greater than 1.2(--unlock-delay)")
# Process options
self.open_list = self.get_list(self.opentype, OPENMAP_R)
self.lock_list = self.get_list(self.locktype, LOCKMAP_R)
self.open2_list = self.get_list(self.opentype2, OPENMAP_R)
self.lock2_list = self.get_list(self.locktype2, LOCKMAP_R)
self.setl_list = self.get_list(self.setlock, SLOCKMAP_R)
if self.open_list is None:
self.opts.error("invalid type given in --opentype [%s]" % self.opentype)
if self.lock_list is None:
self.opts.error("invalid type given in --locktype [%s]" % self.locktype)
if self.open2_list is None:
self.opts.error("invalid type given in --opentype2 [%s]" % self.opentype2)
if self.lock2_list is None:
self.opts.error("invalid type given in --locktype2 [%s]" % self.locktype2)
if self.setl_list is None:
self.opts.error("invalid type given in --setlock [%s]" % self.setlock)
def lock_setup(self, **kwargs):
"""Setup for locking tests:
- start different processes if needed
- start the remote procedure server on other clients if needed
- mount the exported file system on remote clients
- mount the exported file system locally for each extra
process if different NFS options are specified
- mount the exported file system locally for the main process
- call setup()
Arguments are passed to the main setup() method
"""
# List of local(index=0) and remote(index=1) ProcInfo items
self.proc_info_list = ([], [])
# Find how many extra processes and clients should be started
nclients = 0
nprocesses = 0
for tname in self.testlist:
ncount = TEST_CLIENT_DICT.get(tname, 0)
nclients = max(nclients, ncount)
ncount = TEST_PROCESS_DICT.get(tname, 0)
nprocesses = max(nprocesses, ncount)
client_list = self.process_client_option(count=nclients)
self.verify_client_option(TEST_CLIENT_DICT)
nfsopts_list = self.process_client_option("nfsopts", remote=False, count=nprocesses)
# Flush log file before starting child processes
self.flush_log()
# Start remote procedure server(s) locally
for nfsopt_item in nfsopts_list:
self.create_proc_info(nfsopt_item)
# Start remote procedure server(s) remotely
for client_item in client_list:
self.create_proc_info(client_item)
# Unmount server on local host
self.umount()
# Mount server on local host
self.mount()
# Call base object setup method
self.setup(**kwargs)
def start_rexec(self, clientobj):
"""Start remote procedure server locally or on the host given by
the client object.
Set up the remote server with helper functions to lock and
unlock a file.
clientobj:
Client object where the remote procedure server will be started
"""
# Start remote procedure server on given client
execobj = self.create_rexec(clientobj.host)
# Setup function to lock and unlock a file
execobj.rimport("fcntl", ["fcntl", "F_SETLK"])
execobj.rimport("struct")
execobj.rimport("signal")
execobj.rcode(getlock)
# Set SIGALRM handler to do nothing but not ignoring the signal
# just to interrupt a blocked lock
execobj.reval("signal.signal(signal.SIGALRM, lambda signum,frame:None)")
return ProcInfo(clientobj, execobj)
def create_proc_info(self, proc_item):
"""Create a ProcInfo object and mount server if necessary"""
# Create a copy of the process item
client_args = dict(proc_item)
# Create a Host object for the given client
client_name = client_args.pop("client", "")
clientobj = self.create_host(client_name, **client_args)
if proc_item.get("mount"):
# Mount only if necessary
clientobj.umount()
clientobj.mount()
# Start a remote procedure server locally or remotely
pinfo = self.start_rexec(clientobj)
self.proc_info_list[pinfo.remote].append(pinfo)
return pinfo
def get_info_list(self, lock_list, remote=0):
"""Return a list of ProcInfo objects representing the locks in the
given list.
lock_list:
List of lock definitions where each definition is given by a
tuple (offset, length)
remote:
Using a remote client or a local process [default: 0]
"""
idx = 0
info_list = []
x_info_list = self.proc_info_list[remote]
for offset, length in lock_list:
# Set the lock range in the ProcInfo object and add it to the list
info_list.append(x_info_list[idx].lock_range(offset, length))
idx += 1
return info_list
def get_time(self):
"""Return the number of seconds since the object was instantiated"""
return time.time() - self.st_time
def get_opts_list(self, sflag=True, oflag=True, lflag=True, coflag=True, clflag=True):
"""Return a list of all the permutations given by all option lists
sflag:
If true, use blocking and non-blocking locks
oflag:
If true, use open type of read, write and rdwr
lflag:
If true, use lock type of read, write and unlock
coflag:
If true, use open type of read, write and rdwr on second
process or client
clflag:
If true, use lock type of read, write and unlock on second
process or client
"""
ret = []
setl_list = self.setl_list if sflag else [None]
open_list = self.open_list if oflag else [None]
lock_list = self.lock_list if lflag else [None]
open2_list = self.open2_list if coflag else [None]
lock2_list = self.lock2_list if clflag else [None]
for stype in setl_list:
for oltype in open_list:
for ltype in lock_list:
for octype in open2_list:
for ctype in lock2_list:
ret.append({
'stype' : stype,
'oltype' : oltype,
'ltype' : ltype,
'octype' : octype,
'ctype' : ctype,
})
return ret
def open_file(self, otype, pinfo=None):
"""Open file with given open type on either local or remote client
otype:
Open type, either O_RDONLY, O_WRONLY or O_RDWR
pinfo:
ProcInfo object to open file on a different process or client
[default: None]
"""
filename = self.files[0]
# Use the correct mount point in the full path of file
if pinfo is None:
absfile = self.abspath(filename)
else:
absfile = pinfo.clientobj.abspath(filename)
if otype & os.O_WRONLY == os.O_WRONLY:
ostr = "writing"
elif otype & os.O_RDWR == os.O_RDWR:
ostr = "reading and writing"
else:
ostr = "reading"
if pinfo:
# OPEN on different process or remote client
pstr = "client" if pinfo.remote else "process"
self.dprint('DBG2', "Open file for %s [%s] on %s %s" % (ostr, filename, pinfo.proc_ordnum, pstr))
fd = pinfo.run(os.open, absfile, otype)
else:
# OPEN locally
self.dprint('DBG2', "Open file for %s [%s]" % (ostr, filename))
fd = os.open(absfile, otype)
return fd
def do_lock_test(self, fd, ltype, offset=None, length=None, msg="", submsg=None, stype=F_SETLK, block=False, error=0, pinfo=None):
"""Do the actual lock on a file given by the file descriptor
fd:
File descriptor of file to lock
ltype:
Lock type: F_RDLCK, F_WRLCK or F_UNLCK
offset:
Starting offset of byte range lock [default: None]
If offset is None then use the offset from the ProcInfo
object given by pinfo
length:
Length of byte range lock [default: None]
If length is None then use the length from the ProcInfo
object given by pinfo
msg:
Test message to display [default: ""]
submsg:
Subtest message to display [default: None]
stype:
Blocking lock type: F_SETLK or F_SETLKW [default: F_SETLK]
block:
Expect lock to block [default: False]
error:
Expected locking error [default: 0]
pinfo:
ProcInfo object to lock file on a different process or client
[default: None]
"""
try:
fmsg = ""
pexpr = False
ioerrno = 0
if pinfo:
# Use the lock range given in the ProcInfo object
offset = pinfo.offset if offset is None else offset
length = pinfo.length if length is None else length
# Set up debugging message options
lmsg = "Unlock" if ltype == F_UNLCK else "Lock"
smsg = "F_SETLK" if stype == F_SETLK else "F_SETLKW"
(start, end) = get_range(offset, length)
info = "%s file (%s, %s) off=%d len=%d range(%d, %d)" % (lmsg, LOCKMAP[ltype], smsg, offset, length, start, end)
if pinfo:
# Lock file in different process or remote client
pstr = "client" if pinfo.remote else "process"
self.dprint('DBG1', info + " on %s %s @%.2f" % (pinfo.proc_ordnum, pstr, self.get_time()))
nowait = True if stype == F_SETLKW else False
out = pinfo.run("getlock", fd, ltype, offset, length, stype, self.lockw_timeout, NOWAIT=nowait)
if nowait:
# It is a blocking lock, it could block if overlapping range
# Poll Rexec object to make sure the lock is blocked if it
# is expected to block
pexpr = pinfo.poll(0.1)
if pexpr:
if block:
# Expected to block, but did not
fmsg = ": lock did not block"
elif error != errno.EAGAIN:
# Get lock results
out = pinfo.results()
else:
# Lock file locally
self.dprint('DBG1', info)
getlock(fd, ltype, offset, length, stype, self.lockw_timeout)
except IOError as ioerr:
# Set up fail message if expecting no errors
ioerrno = ioerr.errno
errstr = errno.errorcode[ioerr.errno]
self.dprint("DBG7", "Got error %s" % errstr)
fmsg = ": got error %s" % errstr
if error:
# Expecting an error
(expr, fmsg) = get_ioerror(ioerrno, error)
else:
# Not expecting an error
expr = not ioerrno and (not block or not pexpr)
self.test(expr, msg, subtest=submsg, failmsg=fmsg)
return ioerrno is None
def wait_for_lock(self, fd, info_list, lockmsg, submsg_list):
"""Wait for blocked lock
fd:
File descriptor of file holding the current lock, so it will
be unlocked to let the blocked lock be granted
info_list:
List of ProcInfo objects with info for each blocked lock
on a different process or client
lockmsg:
Description of current lock
submsg_list:
List of subtest messages to display for each lock given in
info_list
"""
fmsg = ""
out = None
expr = False
# Flag used for keeping track of the time since the first client
# unlocked the file and timed out if blocked lock is not granted
sl_time = 0
# Flag used for waiting to unlock file on the first client
stime = time.time()
# Flag used to verify if the unlock of the first client was done
need_unlock = True
# Polling granularity
delta = self.unlock_delay/5.0
self.dprint('DBG3', "Wait %.2f secs to unlock conflicting lock @%.2f" % (self.unlock_delay, self.get_time()))
dbgmsg = "Check if blocked lock is still waiting"
while True:
self.dprint('DBG3', "%s @%.2f" % (dbgmsg, self.get_time()))
if need_unlock and (expr or time.time() - stime >= self.unlock_delay):
# Unlock current file lock so the blocked lock could be granted
msg = "Unlocking full file after delay should be granted"
self.do_lock_test(fd, F_UNLCK, 0, 0, msg, lockmsg)
if expr:
# Blocked lock has already been granted
break
need_unlock = False
sl_time = time.time()
self.dprint('DBG3', "Wait up to %d secs to check if blocked lock has been granted @%.2f" % (self.lockw_timeout, self.get_time()))
dbgmsg = "Check if blocked lock has been granted"
delta = self.lockw_timeout/30.0
if delta < 0.2:
delta = 0.2
delta_time = delta
idx = 0
ordnum = ""
for pinfo in info_list:
submsg = submsg_list[idx]
idx += 1
if len(info_list) > 1:
ordnum = "%s " % ordinal_number(idx)
if pinfo.need_unlock is not None:
# This lock has already been granted
continue
if pinfo.poll(delta_time):
out = None
try:
# Blocking lock just returned
self.dprint('DBG3', "Getting results from %sblocked lock @%.2f" % (ordnum, self.get_time()))
out = pinfo.results()
expr = True
except Exception as e:
# Unable to get results from blocked lock
if getattr(e, "errno", None) == errno.EINTR:
self.test(False, "Timeout waiting for %sblocked lock to be granted" % ordnum, subtest=submsg)
else:
self.test(False, "Error while getting results from %sblocked lock" % ordnum, subtest=submsg, failmsg=": %s" % e)
pinfo.result = out
pinfo.need_unlock = need_unlock
delta_time = min(delta/10.0, 0.01)
if not need_unlock:
if [x.need_unlock for x in info_list].count(None) == 0:
# All locks have been granted or timed out
break
idx = 0
for pinfo in info_list:
submsg = submsg_list[idx]
idx += 1
if pinfo.need_unlock:
self.test(not pinfo.result, "Blocked lock is granted before conflicting lock was unlocked", subtest=submsg)
else:
self.test(pinfo.result, "Blocked lock is granted after conflicting lock is released", subtest=submsg, failmsg=fmsg)
def basic_lock(self, info_list, oltype, ltype, octype, ctype, stype):
"""This is the main locking method for overlapping and non-overlapping
tests. This method does the following:
1. Open file locally
2. Lock file locally -- this is the conflicting lock
3. Open file on a different process or remote client
4. Lock file on a different process or remote client
5. If locks do not overlap, verify both locks are granted
6. If using a blocking lock on an overlapping range, then wait
for the number of seconds given by option unlock-delay and
verify the blocking lock is not granted until the conflicting
lock has been unlocked at the end of the wait period. Once the
conflicting lock has been unlocked verify the blocked lock
is granted
7. If using a non-blocking lock on an overlapping range, verify
the correct error is returned
8. Unlock both the local and remote locks
info_list:
List of ProcInfo objects with info for each extra lock to take
on a different process or client
oltype:
Open type to use on local file
ltype:
Lock type to use on local file
octype:
Open type to use on second file (other process or remote)
ctype:
Lock type to use on second file (other process or remote)
stype:
Either a blocking or non-blocking lock
"""
try:
err = 0
fdl = None
if self.subtraces:
self.trace_start()
if self.createtraces or self.subtraces:
# Have a marker on the packet trace for the running test,
# this will make the client send a LOOKUP with the test
# info as the file name
self.insert_trace_marker(self.sub_testname)
# Find if ranges overlap
isoverlap = info_list[0].isoverlap
pstr = "client" if info_list[0].remote else "process"
smsg1 = ", lock1(%s, %s, %s)" % (OPENMAP[oltype], LOCKMAP[ltype], SLOCKMAP[stype])
smsg_list = []
for i in range(len(info_list)):
smsgx = ", lock%d(%s, %s, %s)" % (i+2, OPENMAP[octype], LOCKMAP[ctype], SLOCKMAP[stype])
smsg_list.append(smsgx)
# Set up main test message
error = 0
blocking = False
ostr = "" if isoverlap else "non-"
if ctype == F_RDLCK and octype == os.O_WRONLY or \
ctype == F_WRLCK and octype == os.O_RDONLY:
error = errno.EBADF
imsg = "return %s" % errno.errorcode[error]
elif not isoverlap or (ltype == F_RDLCK and ctype == F_RDLCK):
error = 0
imsg = "be granted"
if isoverlap:
imsg += " since both locks are %s" % LOCKMAP[ltype]
elif stype == F_SETLKW:
error = 0
imsg = "block"
blocking = True
elif ltype != ctype or (ltype == F_WRLCK and ctype == ltype):
error = errno.EAGAIN
imsg = "return %s" % errno.errorcode[error]
else:
error = 0
imsg = "be granted"
lmsg = "be granted"
if ltype == F_RDLCK and oltype == os.O_WRONLY or \
ltype == F_WRLCK and oltype == os.O_RDONLY:
err = errno.EBADF
lmsg = "return %s" % errno.errorcode[err]
# Open file on main process and lock it, this will become the
# conflicting lock
fdl = self.open_file(oltype)
submsg = " should %s%s" % (lmsg, smsg1)
msg = "Locking byte range"
self.do_lock_test(fdl, ltype, self.offset, self.length, msg, submsg, stype=stype, error=err)
if not err:
idx = 0
for pinfo in info_list:
pinfo.fd = self.open_file(octype, pinfo)
submsg = " should %s%s" % (imsg, smsg_list[idx])
msg = "Locking with %soverlapping range on %s %s" % (ostr, pinfo.proc_ordnum, pstr)
locked = self.do_lock_test(pinfo.fd, ctype, msg=msg, submsg=submsg, stype=stype, error=error, pinfo=pinfo, block=blocking)
idx += 1
if blocking:
# Wait for blocked lock to be granted by unlocking the
# conflicting lock
self.wait_for_lock(fdl, info_list, smsg1, smsg_list)
else:
# No locking conflict so unlock local file
msg = "Unlocking full file should be granted"
self.do_lock_test(fdl, F_UNLCK, 0, 0, msg, smsg1)
if not locked and error != errno.EBADF:
xmsg = "be granted"
if ctype == F_RDLCK and octype == os.O_WRONLY or \
ctype == F_WRLCK and octype == os.O_RDONLY:
err = errno.EBADF
xmsg = "return %s" % errno.errorcode[err]
idx = 0
for pinfo in info_list:
submsg = " should %s%s" % (xmsg, smsg_list[idx])
msg = "Locking byte range on %s %s" % (pinfo.proc_ordnum, pstr)
self.do_lock_test(pinfo.fd, ctype, msg=msg, submsg=submsg, stype=stype, error=err, pinfo=pinfo)
idx += 1
if error != errno.EBADF:
idx = 0
for pinfo in info_list:
msg = "Unlocking full file on %s %s should be granted" % (pinfo.proc_ordnum, pstr)
self.do_lock_test(pinfo.fd, F_UNLCK, 0, 0, msg, smsg_list[idx], pinfo=pinfo)
idx += 1
except:
self.test(False, traceback.format_exc())
finally:
# Close open files
if fdl is not None:
os.close(fdl)
for pinfo in info_list:
pinfo.close_fd()
if self.subtraces:
self.trace_stop()
self.trace_open()
self.pktt.close()
def do_basic_lock(self, info_list, overlap=False):
"""This is the main locking method for testing all different
permutations of the same test by varying the open type of both
files, the locking type and for blocking and non-blocking locks.
info_list:
List of ProcInfo objects with info for each extra lock to take
on a different process or client
overlap:
True if range is expected to overlap
"""
# Find if ranges overlap
(start1, end1) = get_range(self.offset, self.length)
ridx = 2
for pinfo in info_list:
(start2, end2) = get_range(pinfo.offset, pinfo.length)
isoverlap = (start1 <= end2 and start2 <= end1)
pinfo.isoverlap = isoverlap
# Check if ranges overlap when expected
fmsg = ": range1(%d, %d), range%d(%d, %d)" % (start1, end1, ridx, start2, end2)
if overlap and not isoverlap:
self.test(False, "Range does not overlap", failmsg=fmsg)
return
elif not overlap and isoverlap:
self.test(False, "Range overlaps", failmsg=fmsg)
return
ridx += 1
testidx = 1
for item in self.get_opts_list():
stype = item['stype']
oltype = item['oltype']
ltype = item['ltype']
octype = item['octype']
ctype = item['ctype']
self.sub_testname = "%s_%03d" % (self.testname, testidx)
if self.tverbose == 2:
self.dprint("INFO", "Running %s" % self.sub_testname)
# Reset ProcInfo objects for next test
expr = self.nfs_version < 4
for pinfo in info_list:
expr = expr or pinfo.clientobj.nfs_version < 4
pinfo.reset()
if expr or info_list[0].remote:
# Expect NFS errors only if NFS version < 4 or a remote client
self.set_nfserr_list(
nfs3list=[nfs3_const.NFS3ERR_NOENT, nfs3_const.NFS3ERR_NOTEMPTY],
nfs4list=[nfs4_const.NFS4ERR_NOENT, nfs4_const.NFS4ERR_DENIED],
nlm4list=[nlm4_const.NLM4_BLOCKED, nlm4_const.NLM4_DENIED],
)
# Do actual test
self.basic_lock(info_list, oltype, ltype, octype, ctype, stype)
testidx += 1
def btest01_test(self):
"""Basic locking tests
These tests verify that a lock is granted using various arguments
to fcntl. These include blocking and non-blocking locks, read or
write locks, where the file is opened either for reading, writing
or both. It also checks different ranges including limit conditions.
"""
self.test_group("Basic locking tests")
nmax = 0x7fffffff if self.nfs_version == 2 else 0x7fffffffffffffff
tlist = [ (0, 0), (0, 1), (1, 0), (0, self.length),
(self.offset, self.length), (self.offset, 0),
(self.offset, 1), (0, nmax), (1, nmax), (nmax, 1),
(nmax, 0), (0, -1), (-1, 0) ]
testidx = 1
for offset, length in tlist:
offstr = "NMAX" if offset == nmax else str(offset)
lenstr = "NMAX" if length == nmax else str(length)
for item in self.get_opts_list(coflag=False, clflag=False):
try:
fd = None
self.sub_testname = "%s_%03d" % (self.testname, testidx)
if self.tverbose > 1:
self.dprint("INFO", "Running %s" % self.sub_testname)
if self.subtraces:
self.trace_start()
if self.createtraces or self.subtraces:
# Have a marker on the packet trace for the running
# test, this will make the client send a LOOKUP with
# the test info as the file name
self.insert_trace_marker(self.sub_testname)
testidx += 1
stype = item['stype']
oltype = item['oltype']
ltype = item['ltype']
lerr = 0
uerr = 0
if offset < 0 or length < 0:
lerr = errno.EINVAL
uerr = errno.EINVAL
elif ltype == F_RDLCK and oltype == os.O_WRONLY or \
ltype == F_WRLCK and oltype == os.O_RDONLY:
lerr = errno.EBADF
lmsg = "return %s" % errno.errorcode[lerr] if lerr else "be granted"
umsg = "return %s" % errno.errorcode[uerr] if uerr else "be granted"
submsg = "open(%s) lock(%s, %s)" % (OPENMAP[oltype], LOCKMAP[ltype], SLOCKMAP[stype])
lsubmsg = " should %s, %s" % (lmsg, submsg)
usubmsg = " should %s, %s" % (umsg, submsg)
# Open file
fd = self.open_file(oltype)
msg = "Unlocking byte range (off:%s, len:%s) while file is not locked" % (offstr, lenstr)
self.do_lock_test(fd, F_UNLCK, offset, length, msg, usubmsg, stype=stype, error=uerr)
msg = "Locking byte range (off:%s, len:%s)" % (offstr, lenstr)
locked = self.do_lock_test(fd, ltype, offset, length, msg, lsubmsg, stype=stype, error=lerr)
if locked:
msg = "Unlocking byte range (off:%s, len:%s)" % (offstr, lenstr)
self.do_lock_test(fd, F_UNLCK, offset, length, msg, usubmsg, stype=stype, error=uerr)
except:
self.test(False, traceback.format_exc())
finally:
# Close open file
if fd is not None:
os.close(fd)
if self.subtraces:
self.trace_stop()
self.trace_open()
self.pktt.close()
def ntest01(self, remote=0):
"""Locking non-overlapping range from a second process where end2 < start1
process1: |------------------|
process2: |--------|
"""
pstr = "client" if remote else "process"
self.test_group("Locking non-overlapping range from a second %s where end2 < start1" % pstr)
self.do_basic_lock(self.get_info_list([(0, int(self.offset/2))], remote))
def ntest02(self, remote=0):
"""Locking non-overlapping range from a second process where end2 == start1 - 1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
self.test_group("Locking non-overlapping range from a second %s where end2 == start1 - 1" % pstr)
self.do_basic_lock(self.get_info_list([(0, self.offset)], remote))
def ntest03(self, remote=0):
"""Locking non-overlapping range from a second process where start2 > end1
process1: |------------------|
process2: |--------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset + self.length + int(self.length/2)
length2 = int(self.length/2)
self.test_group("Locking non-overlapping range from a second %s where start2 > end1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, length2)], remote))
self.test_group("Locking non-overlapping range from a second %s where start2 > end1 and end2 == EOF" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, 0)], remote))
def ntest04(self, remote=0):
"""Locking non-overlapping range from a second process where start2 == end1 + 1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset + self.length
self.test_group("Locking non-overlapping range from a second %s where start2 == end1 + 1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, self.length)], remote))
self.test_group("Locking non-overlapping range from a second %s where start2 == end1 + 1 and end2 == EOF" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, 0)], remote))
def otest01(self, remote=0):
"""Locking same range from a second process
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
self.test_group("Locking same range from a second %s" % pstr)
self.do_basic_lock(self.get_info_list([(self.offset, self.length)], remote), overlap=True)
def otest02(self, remote=0):
"""Locking overlapping range from a second process where start2 < start1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset - int(self.length/2)
if offset2 < 0:
offset2 = 0
length2 = self.offset + int(self.length/2) - offset2
self.test_group("Locking overlapping range from a second %s where start2 < start1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, length2)], remote), overlap=True)
if offset2 > 0:
length2 = self.offset + int(self.length/2)
self.test_group("Locking overlapping range from a second %s where start2 < start1 and start2 == 0" % pstr)
self.do_basic_lock(self.get_info_list([(0, length2)], remote), overlap=True)
def otest03(self, remote=0):
"""Locking overlapping range from a second process where end2 > end1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset + int(self.length/2)
self.test_group("Locking overlapping range from a second %s where end2 > end1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, self.length)], remote), overlap=True)
self.test_group("Locking overlapping range from a second %s where end2 > end1 and end2 == EOF" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, 0)], remote), overlap=True)
def otest04(self, remote=0):
"""Locking overlapping range from a second process where range2 is entirely within range1
process1: |------------------|
process2: |--------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset + int(self.length/4)
length2 = int(self.length/2)
self.test_group("Locking overlapping range from a second %s where range2 is entirely within range1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, length2)], remote), overlap=True)
def otest05(self, remote=0):
"""Locking overlapping range from a second process where range1 is entirely within range2
process1: |------------------|
process2: |----------------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset - int(self.length/4)
if offset2 < 0:
offset2 = 0
length2 = self.length + int(self.length/2)
self.test_group("Locking overlapping range from a second %s where range1 is entirely within range2" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, length2)], remote), overlap=True)
if offset2 > 0:
length2 = self.offset + self.length + int(self.length/4)
self.test_group("Locking overlapping range from a second %s where range1 is entirely within range2 and start2 == 0" % pstr)
self.do_basic_lock(self.get_info_list([(0, length2)], remote), overlap=True)
self.test_group("Locking overlapping range from a second %s where range1 is entirely within range2 and end2 == EOF" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, 0)], remote), overlap=True)
def otest06(self, remote=0):
"""Locking full file range from a second process"""
pstr = "client" if remote else "process"
self.test_group("Locking full file range from a second %s" % pstr)
self.do_basic_lock(self.get_info_list([(0, 0)], remote), overlap=True)
def otest07(self, remote=0):
"""Locking overlapping range from a second process where end2 == start1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset - self.length + 1
if offset2 < 0:
offset2 = 0
length2 = self.offset - offset2 + 1
self.test_group("Locking overlapping range from a second %s where end2 == start1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, length2)], remote), overlap=True)
if offset2 > 0:
length2 = self.offset + 1
self.test_group("Locking overlapping range from a second %s where end2 == start1 and start2 == 0" % pstr)
self.do_basic_lock(self.get_info_list([(0, length2)], remote), overlap=True)
def otest08(self, remote=0):
"""Locking overlapping range from a second process where start2 == end1
process1: |------------------|
process2: |------------------|
"""
pstr = "client" if remote else "process"
offset2 = self.offset + self.length - 1
self.test_group("Locking overlapping range from a second %s where start2 == end1" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, self.length)], remote), overlap=True)
self.test_group("Locking overlapping range from a second %s where start2 == end1 and end2 == EOF" % pstr)
self.do_basic_lock(self.get_info_list([(offset2, 0)], remote), overlap=True)
def otest09(self, remote=0):
"""Locking overlapping range from multiple processes where range2 and
range3 are entirely within range1
process1: |-----------------------------|
process2: |--------|
process3: |--------|
"""
pstr = "clients" if remote else "processes"
offset2 = self.offset + int(self.length/4)
length2 = int(self.length/4)
lock_list = [
(offset2, length2),
(offset2+length2, length2),
]
self.test_group("Locking overlapping range from multiple %s where " \
"range2 and range3 are entirely within range1" % pstr)
info_list = self.get_info_list(lock_list, remote)
self.do_basic_lock(info_list, overlap=True)
def nptest01_test(self):
"""Locking non-overlapping range from a second process where end2 < start1
process1: |------------------|
process2: |--------|
"""
self.ntest01(remote=0)
def nptest02_test(self):
"""Locking non-overlapping range from a second process where end2 == start1 - 1
process1: |------------------|
process2: |------------------|
"""
self.ntest02(remote=0)
def nptest03_test(self):
"""Locking non-overlapping range from a second process where start2 > end1
process1: |------------------|
process2: |--------|
"""
self.ntest03(remote=0)
def nptest04_test(self):
"""Locking non-overlapping range from a second process where start2 == end1 + 1
process1: |------------------|
process2: |------------------|
"""
self.ntest04(remote=0)
def nctest01_test(self):
"""Locking non-overlapping range from a second client where end2 < start1
client1: |------------------|
client2: |--------|
"""
self.ntest01(remote=1)
def nctest02_test(self):
"""Locking non-overlapping range from a second client where end2 == start1 - 1
client1: |------------------|
client2: |------------------|
"""
self.ntest02(remote=1)
def nctest03_test(self):
"""Locking non-overlapping range from a second client where start2 > end1
client1: |------------------|
client2: |--------|
"""
self.ntest03(remote=1)
def nctest04_test(self):
"""Locking non-overlapping range from a second client where start2 == end1 + 1
client1: |------------------|
client2: |------------------|
"""
self.ntest04(remote=1)
def optest01_test(self):
"""Locking same range from a second process
process1: |------------------|
process2: |------------------|
"""
self.otest01(remote=0)
def optest02_test(self):
"""Locking overlapping range from a second process where start2 < start1
process1: |------------------|
process2: |------------------|
"""
self.otest02(remote=0)
def optest03_test(self):
"""Locking overlapping range from a second process where end2 > end1
process1: |------------------|
process2: |------------------|
"""
self.otest03(remote=0)
def optest04_test(self):
"""Locking overlapping range from a second process where range2 is entirely within range1
process1: |------------------|
process2: |--------|
"""
self.otest04(remote=0)
def optest05_test(self):
"""Locking overlapping range from a second process where range1 is entirely within range2
process1: |------------------|
process2: |----------------------------|
"""
self.otest05(remote=0)
def optest06_test(self):
"""Locking full file range from a second process"""
self.otest06(remote=0)
def optest07_test(self):
"""Locking overlapping range from a second process where end2 == start1
process1: |------------------|
process2: |------------------|
"""
self.otest07(remote=0)
def optest08_test(self):
"""Locking overlapping range from a second process where start2 == end1
process1: |------------------|
process2: |------------------|
"""
self.otest08(remote=0)
def optest09_test(self):
"""Locking overlapping range from multiple processes where range2 and
range3 are entirely within range1
process1: |-----------------------------|
process2: |--------|
process3: |--------|
"""
self.otest09(remote=0)
def octest01_test(self):
"""Locking same range from a second client
client1: |------------------|
client2: |------------------|
"""
self.otest01(remote=1)
def octest02_test(self):
"""Locking overlapping range from a second client where start2 < start1
client1: |------------------|
client2: |------------------|
"""
self.otest02(remote=1)
def octest03_test(self):
"""Locking overlapping range from a second client where end2 > end1
client1: |------------------|
client2: |------------------|
"""
self.otest03(remote=1)
def octest04_test(self):
"""Locking overlapping range from a second client where range2 is entirely within range1
client1: |------------------|
client2: |--------|
"""
self.otest04(remote=1)
def octest05_test(self):
"""Locking overlapping range from a second client where range1 is entirely within range2
client1: |------------------|
client2: |----------------------------|
"""
self.otest05(remote=1)
def octest06_test(self):
"""Locking full file range from a second client"""
self.otest06(remote=1)
def octest07_test(self):
"""Locking overlapping range from a second client where end2 == start1
client1: |------------------|
client2: |------------------|
"""
self.otest07(remote=1)
def octest08_test(self):
"""Locking overlapping range from a second client where start2 == end1
client1: |------------------|
client2: |------------------|
"""
self.otest08(remote=1)
def octest09_test(self):
"""Locking overlapping range from multiple clients where range2 and
range3 are entirely within range1
client1: |-----------------------------|
client2: |--------|
client3: |--------|
"""
self.otest09(remote=1)
################################################################################
# Entry point
x = LockTest(usage=USAGE, testnames=TESTNAMES, testgroups=TESTGROUPS, sid=SCRIPT_ID)
try:
# Call setup
x.lock_setup(nfiles=1)
# Run all the tests
x.run_tests()
except Exception:
x.test(False, traceback.format_exc())
finally:
x.cleanup()
x.exit()
|