This page appears in Guidelines for Writing PTL Tests.
Excerpt |
---|
Main Parts of a PTL TestYou can think of a PTL test as having 3 parts:
Using AttributesMany PTL commands take an attribute dictionary.
Setting Up Your EnvironmentThe idea here is to create an environment which can run the test no matter what machine the test is being run on. You may need to create queues, nodes, or resources, or set attributes, etc. First you need to set up your vnode(s). This is a required step because if you don’t, the natural vnode will be left as is. This means the vnode will have different resources depending on what machine the test is run on. This can be done in one of two ways:
After you set up your vnodes, you might need to set attributes on servers or queues or even create new queues or resources. This is all done via the self.server.manager() call. Examples of Setting up Environment
Creating Your Test WorkloadUsually to run a test you need to submit jobs or reservations. These are of the form:
OR
The attribute dictionary usually consists of the resources (e.g. Resource_List.ncpus or Resource_List.select) and maybe other attributes like ATTR_o. To submit a job to another queue, use ATTR_queue. This just creates a PTL job or reservation object. By default these jobs will sleep for 100 seconds and exit. To change the sleep time of a job, you do ‘j.set_sleep_time(N)’ Finally you submit your job/reservation.
Many tests require more than one reservation. Follow the above steps multiple times for those. Once you have submitted your job or reservation, you should check if it is in the correct state.
As you are running your test, you should make sure most steps have correctly completed. This is mostly done through expect(). The expect() function will query PBS 60 times once every half seconds (total of 30 seconds) to see if the attributes are true. If after 60 attempts the attribute is still not true, a PtlExpectError exception will be raised. Running Your TestChecking Your ResultsThis is when you check to see if your test has correctly passed. To do this you will either use self.server.expect() as described above, log_match(), or the series of assert functions provided by unittest. The most useful asserts are self.assertTrue(), self.assertFalse(), self.assertEquals(). There are asserts for all the normal conditional operators (even the in operator). For example, self.assertGreater(a, b) tests a > b. Each of the asserts take a final argument that is a message which is printed if the assertion fails. The log_match() function is on each of the daemon objects (e.g. self.server, self.mom, self.scheduler, etc). Examples of Checking Results
|