2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <sys/types.h>
29 Test that the new session ID is correctly returned to the caller on
30 dm_create_session when the oldsid parameter is not DM_NO_SESSION.
32 Test to make sure that DM_NO_TOKEN does not work if the session ID
35 Both are needed so that session assumption works correctly. The
36 test creates a session, queries the session, assumes the session,
37 then attempts to check the event list of the old session ID while
40 The only parameter is the pathname of a DMAPI filesystem. If it is
41 working correctly, you should get the error message:
45 Any message containing the word FAILURE indicates a problem.
49 dm_sessid_t sid = DM_NO_SESSION; /* session ID of original session */
50 dm_sessid_t newsid = DM_NO_SESSION; /* session ID after session resumed */
51 dm_eventset_t eventlist;
58 char buffer[DM_SESSION_INFO_LEN];
67 fprintf(stderr, "usage:\t%s filesystem\n", Progname);
71 /* Initialize the DMAPI interface and obtain a session ID, then verify
72 that the filesystem supports DMAPI.
75 if (setup_dmapi(&sid))
78 if (dm_path_to_handle(argv[1], &hanp, &hlen)) {
79 perror("FAILURE: can't get handle for filesystem");
83 /* Query the session just to make sure things are working okay. */
85 if (dm_query_session(sid, sizeof(buffer), buffer, &rlen)) {
86 errno_msg("FAILURE: can't query the original session ID %d",
90 fprintf(stdout, "Initial session ID: %d\n", sid);
91 fprintf(stdout, "Initial session message length: '%zd'\n", rlen);
93 fprintf(stdout, "Initial session message: '%s'\n", buffer);
96 /* Now try to assume the session. */
98 if (dm_create_session(sid, "this is a new message", &newsid)) {
99 fprintf(stderr, "FAILURE: can't assume session %d\n", sid);
103 /* Now query the new session. */
105 if (dm_query_session(newsid, sizeof(buffer), buffer, &rlen)) {
106 errno_msg("FAILURE: can't query the assumed session ID %d",
110 fprintf(stdout, "Assumed session ID: %d\n", newsid);
111 fprintf(stdout, "Assumed session message length: '%zd'\n", rlen);
113 fprintf(stdout, "Assumed session message: '%s'\n", buffer);
116 /* Get rid of the new session as we are done with it. */
118 if (dm_destroy_session(newsid)) {
119 fprintf(stderr, "FAILURE: Can't shut down assumed session %d\n",
124 /* Now verify that DM_NO_TOKEN will not work with the old session ID,
125 which is now invalid.
128 DMEV_ZERO(eventlist);
130 if (dm_get_eventlist(sid, hanp, hlen, DM_NO_TOKEN, DM_EVENT_MAX,
131 &eventlist, &nelem) == 0) {
132 fprintf(stderr, "FAILURE: dm_get_eventlist() worked when it "
133 "should have failed!\n");
136 if (errno != ESRCH) {
138 if (errno != EINVAL) {
140 errno_msg("FAILURE: unexpected errno");
143 fprintf(stdout, "SUCCESS!\n");