PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/src/suites/os/smf/tests/libscf-low/templates/scf_tmpl_value_name_constraint/scf_tmpl_value_name_constraint_009.c

https://bitbucket.org/illumos/illumos-stc
C | 178 lines | 112 code | 22 blank | 44 comment | 24 complexity | 8b05ed900519a506714c50c97e04b078 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License (the "License").
  6. * You may not use this file except in compliance with the License.
  7. *
  8. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. * or http://www.opensolaris.org/os/licensing.
  10. * See the License for the specific language governing permissions
  11. * and limitations under the License.
  12. *
  13. * When distributing Covered Code, include this CDDL HEADER in each
  14. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. * If applicable, add the following below this CDDL HEADER, with the
  16. * fields enclosed by brackets "[]" replaced with your own identifying
  17. * information: Portions Copyright [yyyy] [name of copyright owner]
  18. *
  19. * CDDL HEADER END
  20. */
  21. /*
  22. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. #pragma ident "%Z%%M% %I% %E% SMI"
  26. #ifdef __stc_assertion__
  27. /*
  28. * ASSERTION: scf_tmpl_value_name_constraint_009
  29. *
  30. * DESCRIPTION:
  31. * scf_tmpl_value_name_constraint gets the correct error
  32. * from a property pattern that has no constraints
  33. *
  34. * STRATEGY:
  35. * 1. Get the property group
  36. * 2. Get the preoprty pattern
  37. * 3. Get the constraint values
  38. * 4. Verify the set of constraints against the
  39. * expected set
  40. *
  41. * INTERFACES: scf_tmpl_value_name_constraint
  42. *
  43. */
  44. #endif /* __stc_assertion__ */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <strings.h>
  48. #include <errno.h>
  49. #include <libscf.h>
  50. #include <libscftest-tmpl.h>
  51. int
  52. main()
  53. {
  54. scf_error_t exp_scf_err;
  55. scf_values_t names;
  56. scf_prop_tmpl_t *p;
  57. scf_pg_tmpl_t *t = NULL;
  58. scf_handle_t *h = NULL;
  59. char *instance_fmri = NULL;
  60. char *property_group = "foobar";
  61. char *property = "foobar_prop";
  62. int result = PASS;
  63. char **c;
  64. int i;
  65. instance_fmri = SCFTEST_TEMPLATES_INST;
  66. (void) fprintf(stdout, "\n--ASRT: "
  67. "scf_tmpl_value_name_constraint gets the correct error\n"
  68. "from a property pattern that has no constraints\n"
  69. "\tINTERFACES: scf_tmpl_value_name_constraint()\n");
  70. /* Create a connection handle; do not bind it to the repository */
  71. if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
  72. result = UNRESOLVED;
  73. (void) fprintf(stdout, "--DIAG: "
  74. "scf_handle_create() failed\n\t"
  75. "EXPECTED: handle != NULL, no error\n\t"
  76. "RETURNED: handle == NULL, %s\n",
  77. scf_strerror(scf_error()));
  78. goto out;
  79. } /* scf_handle_create() */
  80. /* Bind the handle to the repository */
  81. if (scf_handle_bind(h) != 0) {
  82. result = UNRESOLVED;
  83. (void) fprintf(stdout, "--DIAG: "
  84. "Error connecting handle to repository: "
  85. "scf_handle_bind() failed\n\t"
  86. "EXPECTED: no error\n\t"
  87. "RETURNED: %s\n",
  88. scf_strerror(scf_error()));
  89. goto out;
  90. }
  91. if ((t = scf_tmpl_pg_create(h)) == NULL) {
  92. result = UNRESOLVED;
  93. (void) fprintf(stdout, "--DIAG: "
  94. "Error creating property group template: "
  95. "scf_tmpl_pg_create() failed\n\t"
  96. "EXPECTED: no error\n\t"
  97. "RETURNED: %s\n",
  98. scf_strerror(scf_error()));
  99. goto out;
  100. }
  101. /* VERIFY ASSERTION */
  102. exp_scf_err = SCF_ERROR_NONE;
  103. if (scftest_tmpl_get_by_pg_name(instance_fmri, NULL, property_group,
  104. NULL, t, 0, &exp_scf_err) == -1 || exp_scf_err != PASS) {
  105. result = UNRESOLVED;
  106. (void) fprintf(stdout, "--DIAG: scf_tmpl_get_by_pg_name() "
  107. "failed to get the property group."
  108. "RETURNED: %s\n", scf_strerror(scf_error()));
  109. goto out;
  110. }
  111. if ((p = scf_tmpl_prop_create(h)) == NULL) {
  112. result = UNRESOLVED;
  113. (void) fprintf(stdout, "--DIAG: "
  114. "Error creating property pattern : "
  115. "scf_tmpl_prop_create() failed\n\t"
  116. "EXPECTED: no error\n\t"
  117. "RETURNED: %s\n",
  118. scf_strerror(scf_error()));
  119. goto out;
  120. }
  121. exp_scf_err = SCF_ERROR_NONE;
  122. if (scftest_tmpl_get_by_prop(t, property, p, 0,
  123. &exp_scf_err) == -1 || exp_scf_err != PASS) {
  124. result = UNRESOLVED;
  125. (void) fprintf(stdout, "--DIAG: scf_tmpl_get_by_prop() failed "
  126. "to get the property group\n"
  127. "RETURNED: %s\n", scf_strerror(scf_error()));
  128. goto out;
  129. } else {
  130. (void) fprintf(stdout, "--INFO: scf_tmpl_get_by_prop() "
  131. "successfully got a property group template for %s\n",
  132. instance_fmri);
  133. }
  134. exp_scf_err = SCF_ERROR_NOT_FOUND;
  135. if (scftest_tmpl_value_name_constraints(p, &names,
  136. &exp_scf_err) == -1) {
  137. if (names.values.v_astring) {
  138. (void) fprintf(stdout, "--DIAG: "
  139. "Got the following names from "
  140. "scf_tmpl_value_name_constraint()\n");
  141. i = 0;
  142. c = names.values.v_astring;
  143. while (c[i] != NULL) {
  144. (void) fprintf(stdout, "\t%s\n", c[i]);
  145. i++;
  146. }
  147. }
  148. }
  149. out:
  150. if (t)
  151. scf_tmpl_pg_destroy(t);
  152. if (h)
  153. scf_handle_destroy(h);
  154. (void) fprintf(stdout, "--RSLT: %s\n\n", result_tbl[result]);
  155. return (result);
  156. }