ia64/xen-unstable

changeset 13057:671cc928183d

Added a test for xen_vm_get_power_state.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Dec 15 11:00:04 2006 +0000 (2006-12-15)
parents 54eee6fabbee
children ea12d26877a4
files tools/libxen/test/test_bindings.c
line diff
     1.1 --- a/tools/libxen/test/test_bindings.c	Wed Dec 13 18:06:48 2006 -0700
     1.2 +++ b/tools/libxen/test/test_bindings.c	Fri Dec 15 11:00:04 2006 +0000
     1.3 @@ -58,7 +58,8 @@ typedef struct
     1.4  } xen_comms;
     1.5  
     1.6  
     1.7 -static void create_new_vm(xen_session *session);
     1.8 +static xen_vm create_new_vm(xen_session *session);
     1.9 +static void print_vm_power_state(xen_session *session, xen_vm vm);
    1.10  
    1.11  
    1.12  static size_t
    1.13 @@ -244,7 +245,7 @@ int main(int argc, char **argv)
    1.14      xen_string_string_map_free(versions);
    1.15  
    1.16  
    1.17 -    create_new_vm(session);
    1.18 +    xen_vm new_vm = create_new_vm(session);
    1.19      if (!session->ok)
    1.20      {
    1.21          /* Error has been logged, just clean up. */
    1.22 @@ -252,6 +253,16 @@ int main(int argc, char **argv)
    1.23          return 1;
    1.24      }
    1.25  
    1.26 +    print_vm_power_state(session, new_vm);
    1.27 +    if (!session->ok)
    1.28 +    {
    1.29 +        /* Error has been logged, just clean up. */
    1.30 +        xen_vm_free(new_vm);
    1.31 +        CLEANUP;
    1.32 +        return 1;
    1.33 +    }
    1.34 +
    1.35 +    xen_vm_free(new_vm);
    1.36      CLEANUP;
    1.37  
    1.38      return 0;
    1.39 @@ -264,7 +275,7 @@ int main(int argc, char **argv)
    1.40   * allocation patterns can be used, as long as the allocation and free are
    1.41   * paired correctly.
    1.42   */
    1.43 -static void create_new_vm(xen_session *session)
    1.44 +static xen_vm create_new_vm(xen_session *session)
    1.45  {
    1.46      xen_cpu_feature_set *empty_cpu_feature_set =
    1.47          xen_cpu_feature_set_alloc(0);
    1.48 @@ -313,7 +324,7 @@ static void create_new_vm(xen_session *s
    1.49      {
    1.50          fprintf(stderr, "VM creation failed.\n");
    1.51          print_error(session);
    1.52 -        return;
    1.53 +        return NULL;
    1.54      }
    1.55  
    1.56  
    1.57 @@ -327,7 +338,7 @@ static void create_new_vm(xen_session *s
    1.58          fprintf(stderr, "SR lookup failed.\n");
    1.59          print_error(session);
    1.60          xen_vm_free(vm);
    1.61 -        return;
    1.62 +        return NULL;
    1.63      }
    1.64  
    1.65      xen_sr_record_opt sr_record =
    1.66 @@ -354,7 +365,7 @@ static void create_new_vm(xen_session *s
    1.67  
    1.68          xen_sr_set_free(srs);
    1.69          xen_vm_free(vm);
    1.70 -        return;
    1.71 +        return NULL;
    1.72      }
    1.73  
    1.74  
    1.75 @@ -384,7 +395,7 @@ static void create_new_vm(xen_session *s
    1.76          xen_vdi_free(vdi0);
    1.77          xen_sr_set_free(srs);
    1.78          xen_vm_free(vm);
    1.79 -        return;
    1.80 +        return NULL;
    1.81      }
    1.82  
    1.83      char *vm_uuid;
    1.84 @@ -407,7 +418,7 @@ static void create_new_vm(xen_session *s
    1.85          xen_vdi_free(vdi0);
    1.86          xen_sr_set_free(srs);
    1.87          xen_vm_free(vm);
    1.88 -        return;
    1.89 +        return NULL;
    1.90      }
    1.91  
    1.92      fprintf(stderr,
    1.93 @@ -420,5 +431,34 @@ static void create_new_vm(xen_session *s
    1.94      xen_vbd_free(vbd0);
    1.95      xen_vdi_free(vdi0);
    1.96      xen_sr_set_free(srs);
    1.97 -    xen_vm_free(vm);
    1.98 +
    1.99 +    return vm;
   1.100  }
   1.101 +
   1.102 +
   1.103 +/**
   1.104 + * Print the power state for the given VM.
   1.105 + */
   1.106 +static void print_vm_power_state(xen_session *session, xen_vm vm)
   1.107 +{
   1.108 +    char *vm_uuid;
   1.109 +    enum xen_vm_power_state power_state;
   1.110 +
   1.111 +    if (!xen_vm_get_uuid(session, &vm_uuid, vm))
   1.112 +    {
   1.113 +        print_error(session);
   1.114 +        return;
   1.115 +    }
   1.116 +
   1.117 +    if (!xen_vm_get_power_state(session, &power_state, vm))
   1.118 +    {
   1.119 +        xen_uuid_free(vm_uuid);
   1.120 +        print_error(session);
   1.121 +        return;
   1.122 +    }
   1.123 +
   1.124 +    printf("VM %s power state is %s.\n", vm_uuid,
   1.125 +           xen_vm_power_state_to_string(power_state));
   1.126 +
   1.127 +    xen_uuid_free(vm_uuid);
   1.128 +}