| 883 | } |
| 884 | |
| 885 | static int test_finalize_deadlock (void) { |
| 886 | cs_error_t error; |
| 887 | unsigned int instance_id; |
| 888 | pthread_t kill_thread; |
| 889 | |
| 890 | test_sig_delivered = 0; |
| 891 | |
| 892 | printf ("%s: initialize\n", __FUNCTION__); |
| 893 | error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART); |
| 894 | if (error != CS_OK) { |
| 895 | fprintf (stderr, "Can't initialize SAM API. Error %d\n", error); |
| 896 | return 1; |
| 897 | } |
| 898 | printf ("%s: register\n", __FUNCTION__); |
| 899 | error = sam_register (&instance_id); |
| 900 | if (error != CS_OK) { |
| 901 | fprintf (stderr, "Can't register. Error %d\n", error); |
| 902 | return 1; |
| 903 | } |
| 904 | |
| 905 | if (instance_id == 1) { |
| 906 | /* |
| 907 | * Sam finalize might block forever, but 5s for us should be enough |
| 908 | */ |
| 909 | pthread_create (&kill_thread, NULL, test_thread_sleep_exit, NULL); |
| 910 | |
| 911 | printf ("%s iid %d: start\n", __FUNCTION__, instance_id); |
| 912 | error = sam_start (); |
| 913 | if (error != CS_OK) { |
| 914 | fprintf (stderr, "Can't start hc. Error %d\n", error); |
| 915 | return 1; |
| 916 | } |
| 917 | |
| 918 | printf ("%s iid %d: call finalize (shouldn't deadlock)\n", __FUNCTION__, instance_id); |
| 919 | error = sam_finalize (); |
| 920 | if (error != CS_OK) { |
| 921 | fprintf (stderr, "Can't finalize sam. Error %d\n", error); |
| 922 | return 1; |
| 923 | } |
| 924 | |
| 925 | printf ("%s iid %d: finalize succeeded\n", __FUNCTION__, instance_id); |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | if (instance_id == 2) { |
| 930 | printf ("%s iid %d: previous sam_finalize deadlocked\n", __FUNCTION__, instance_id); |
| 931 | } |
| 932 | |
| 933 | return 1; |
| 934 | } |
| 935 | |
| 936 | /* |
| 937 | * Test cmap integration + quit policy |
nothing calls this directly
no test coverage detected