changeset 115:c9392253b499

8074478: gpio tests failed IOException while opening pin. Summary: increase wait period to 1 sec. printout rework Reviewed-by: snazarki Contributed-by: alexey.karaksin@oracle.com
author snazarki
date Tue, 10 Mar 2015 13:42:29 +0400
parents 16557858a60c
children 9fa998722ab8
files src/share/linux/native/com/oracle/dio/gpio/gpio.c
diffstat 1 files changed, 30 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Tue Mar 10 13:40:37 2015 +0400
+++ b/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Tue Mar 10 13:42:29 2015 +0400
@@ -226,7 +226,7 @@
     JAVACALL_REPORT_INFO1(JC_DIO, "Read value from pin %d", pinHandle->number);
 
     if(JAVACALL_DIO_FAIL == read_value_from_pin(pinHandle, pVal)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not read value from pin %d", pinHandle->number);
+        //read_value_from_pin print errors
         return JAVACALL_DIO_FAIL;
     };
 
@@ -243,7 +243,7 @@
     JAVACALL_REPORT_INFO2(JC_DIO, "Pin %d write value %d", pinHandle->number, val);
 
     if(JAVACALL_DIO_OK != write_value_to_pin(pinHandle, val)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not write value to GPIO pin %d", pinHandle->number);
+        //write_value_to_pin print errors
         return JAVACALL_DIO_FAIL;
     }
 
@@ -271,7 +271,6 @@
         }
 
         if(JAVACALL_DIO_OK != javacall_gpio_pin_read(pin, &readValue)) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Read operation to port failed, because error with pin %d occurred", pin->number);
             return JAVACALL_DIO_FAIL;
         };
 
@@ -305,7 +304,6 @@
         }
         writeValue = ((val >> iterator) & 0x01) ? JAVACALL_TRUE : JAVACALL_FALSE;
         if(JAVACALL_DIO_OK != javacall_gpio_pin_write(pin, writeValue)) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Write operation to port failed, because error with pin %d occurred", pin->number);
             return JAVACALL_DIO_FAIL;
         };
         iterator++;
@@ -328,12 +326,12 @@
     }
 
     if(JAVACALL_DIO_OK != activate_platform_notifications_to_pin(pinHandle)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not activate notifications for pin %d", pinHandle->number);
+        //activate_platform_notifications_to_pin print errors
         return JAVACALL_DIO_FAIL;
     }
 
     if(JAVACALL_DIO_OK != add_pin_for_polling(pinHandle)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not poll value file for GPIO pin %d", pinHandle->number);
+        //add_pin_for_polling print errors
         return JAVACALL_DIO_FAIL;
     }
 
@@ -351,7 +349,6 @@
     }
     pthread_mutex_lock(&epoll_fd_lock);
     if(JAVACALL_DIO_OK != del_pin_from_polling(pinHandle)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Notifications disable for pin %d failed", pinHandle->number);
         pthread_mutex_unlock(&epoll_fd_lock);
         return JAVACALL_DIO_FAIL;
     }
@@ -373,7 +370,6 @@
 
     pthread_mutex_lock(&epoll_fd_lock);
     if(JAVACALL_DIO_OK != add_port_for_polling(portHandle)) {
-        JAVACALL_REPORT_INFO(JC_DIO, "Fail to start notifications for port");
         pthread_mutex_unlock(&epoll_fd_lock);
         return JAVACALL_DIO_FAIL;
     }
@@ -395,7 +391,6 @@
 
     pthread_mutex_lock(&epoll_fd_lock);
     if(JAVACALL_DIO_OK != del_port_from_polling(portHandle)) {
-        JAVACALL_REPORT_INFO(JC_DIO, "Fail to stop notifications for port");
         pthread_mutex_unlock(&epoll_fd_lock);
         return JAVACALL_DIO_FAIL;
     }
@@ -413,7 +408,6 @@
     GPIOHandle* pinHandle = (GPIOHandle*) handle;
 
     if(JAVACALL_DIO_OK != write_direction_to_file(pinHandle->directionFD, direction, JAVACALL_FALSE)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "There is unexpected error, when configure direction of GPIO pin %d", pinHandle->number);
         return JAVACALL_DIO_FAIL;
     };
     pinHandle->direction = direction;
@@ -448,7 +442,7 @@
             return JAVACALL_DIO_FAIL;
         }
         if(JAVACALL_DIO_OK != javacall_gpio_pin_direction_set(pin, direction)) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Set direction operation to port failed, because error with pin %d occurred", pin->number);
+            //javacall_gpio_pin_direction_set print error messages
             return JAVACALL_DIO_FAIL;
         };
     }
@@ -474,7 +468,7 @@
             JAVACALL_TRIGGER_RISING_EDGE != trigger &&
             JAVACALL_TRIGGER_NONE != trigger &&
             JAVACALL_TRIGGER_BOTH_EDGES != trigger) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Unsupported or invalid trigger value: %d", trigger);
+        JAVACALL_REPORT_WARN1(JC_DIO, "Unsupported or invalid trigger value: %d", trigger);
         return JAVACALL_DIO_INVALID_CONFIG;
     }
     return JAVACALL_DIO_OK;
@@ -507,14 +501,14 @@
     if(pin == PERIPHERAL_CONFIG_DEFAULT){ pin = 2;}
 
     if (0 < port) {
-        JAVACALL_REPORT_ERROR(JC_DIO, "Only port 0 can be accepted");
+        JAVACALL_REPORT_WARN(JC_DIO, "Only port 0 can be accepted");
         return JAVACALL_DIO_NOT_FOUND;
     }
 
     lock_pin_list();
 
     if (JAVACALL_FALSE == check_gpio_pin_is_free(pin)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "GPIO pin %d busy", pin);
+        JAVACALL_REPORT_WARN1(JC_DIO, "GPIO pin %d busy", pin);
         unlock_pin_list();
         return JAVACALL_DIO_BUSY;
     }
@@ -548,7 +542,7 @@
                 if the runtime runs as a non priviledged user - the direction file become writable
                 after the udev script changed the file permission, it takes up to 150 millisec.
             */
-            while (count < 200){
+            while (count < 1000){
                 // restore root privileges temporary
                 restore_privileges();
                 directionFD = open(bufForDirectionFilename, O_WRONLY);
@@ -568,15 +562,14 @@
         }
     }
     if(-1 == directionFD) {
-        JAVACALL_REPORT_ERROR1(JC_DIO,
-                                "Can not open %s file to configure GPIO pin direction",
-                                bufForDirectionFilename);
+        JAVACALL_REPORT_ERROR2(JC_DIO,
+                                "Can not open %s file to configure GPIO pin direction. %s",
+                                bufForDirectionFilename, strerror(errno));
         unlock_pin_list();
         return JAVACALL_DIO_FAIL;
     }
 
     if(JAVACALL_DIO_OK != write_direction_to_file(directionFD, direction, initValue)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not set direction while open GPIO pin %d Open failed", pin);
         close(directionFD);
         unlock_pin_list();
         return JAVACALL_DIO_FAIL;
@@ -600,7 +593,6 @@
     handle->next = NULL;
 
     if(JAVACALL_DIO_OK != fill_value_fd_for_pin(handle)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not fill valueFD for pin %d Open failed", pin);
         close(directionFD);
         javacall_free(handle);
         unlock_pin_list();
@@ -641,7 +633,7 @@
 
     for(; i < pinCount; i++) {
         if(JAVACALL_FALSE == check_gpio_pin_is_free(portsAndPins[i][1])) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "GPIO pin %d busy", portsAndPins[i][1]);
+            JAVACALL_REPORT_WARN1(JC_DIO, "GPIO pin %d busy", portsAndPins[i][1]);
             return JAVACALL_DIO_BUSY;
         }
     }
@@ -658,7 +650,7 @@
         trigger = portsAndPins[i][3];
         pinState = javacall_gpio_pin_open(0, pin, direction, mode, trigger, JAVACALL_FALSE, JAVACALL_TRUE, (javacall_handle*) &pinHandle);
         if(JAVACALL_DIO_OK != pinState) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Can not open pin %d, so port open operation aborted", pin);
+            //javacall_gpio_pin_open print error messages
             close_pins_in_list(listHandle);
             javautil_list_destroy(listHandle);
             return JAVACALL_DIO_FAIL;
@@ -740,14 +732,13 @@
     drop_privileges();
 
     if(-1 == expordFD) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not open %s file to export gpio."
-            "May be, there is necessary superuser rights", EXPORT_FILE_NAME);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can not open %s file to export gpio. %s", EXPORT_FILE_NAME, strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
 
     snprintf(pinNameBuffer, 4, PIN_NAME_TEMPLATE, pinNumber);
     if(-1 == write(expordFD, pinNameBuffer, 4)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can't export GPIO pin %d", pinNumber);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can't export GPIO pin %d. %s", pinNumber, strerror(errno));
         close(expordFD);
         return JAVACALL_DIO_NOT_FOUND;
     };
@@ -768,11 +759,11 @@
     if(-1 != unexportFD) {
         snprintf(nameOfPinBuffer, 4, PIN_NAME_TEMPLATE, pinNumber);
         if(-1 == write(unexportFD, nameOfPinBuffer, 4)) {
-            JAVACALL_REPORT_WARN1(JC_DIO, "Can not unexport GPIO pin %d", pinNumber);
+            JAVACALL_REPORT_WARN2(JC_DIO, "Can not unexport GPIO pin %d. %s", pinNumber, strerror(errno));
         }
         close(unexportFD);
     } else {
-        JAVACALL_REPORT_WARN(JC_DIO, "Can not open unexport file for GPIO");
+        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not open unexport file for GPIO. %s", strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
 
@@ -790,7 +781,7 @@
     get_platform_direction_string(direction, initialValue, &platformDirectionString);
 
     if(-1 == write(dirFD, platformDirectionString, strlen(platformDirectionString))) {
-        JAVACALL_REPORT_ERROR(JC_DIO, "There is unexpected error, when configure direction of GPIO pin");
+        JAVACALL_REPORT_ERROR1(JC_DIO, "There is unexpected error, when configure direction of GPIO pin. %s", strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
 
@@ -804,7 +795,7 @@
 
     lseek(handle->valueFD, 0, SEEK_SET);
     if(-1 == write(handle->valueFD, outValue, 1)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not write value to GPIO pin %d", handle->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can not write value to GPIO pin %d. %s", handle->number, strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
 
@@ -816,7 +807,7 @@
 
     lseek(handle->valueFD, 0, SEEK_SET);
     if(-1 == read(handle->valueFD, inBuffer, 2)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not read value from valueFD file for GPIO pin %d", handle->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can not read value from valueFD file for GPIO pin %d", handle->number, strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
 
@@ -825,7 +816,7 @@
     } else if(49 == inBuffer[0]) {
         *value = JAVACALL_TRUE;
     } else {
-        JAVACALL_REPORT_ERROR3(JC_DIO, "Error values from value GPIO pin %d file was readed: %d %d", handle->number, inBuffer[0], inBuffer[1]);
+        JAVACALL_REPORT_WARN3(JC_DIO, "Error values from value GPIO pin %d file was readed: %d %d", handle->number, inBuffer[0], inBuffer[1]);
         return JAVACALL_DIO_FAIL;
     }
     return JAVACALL_DIO_OK;
@@ -930,7 +921,7 @@
         epoll_descriptor = epoll_create(17);
     }
     if(-1 == epoll_ctl(epoll_descriptor, EPOLL_CTL_ADD, pinHandle->valueFD, new_event)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Add value file of pin %d to polling failed", pinHandle->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Add value file of pin %d to polling failed. %s", pinHandle->number, strerror(errno));
         pthread_mutex_unlock(&epoll_fd_lock);
         javacall_free(new_event);
         javacall_free(poll_data);
@@ -948,7 +939,7 @@
 
     JAVACALL_REPORT_INFO1(JC_DIO, "Remove value file of pin %d from polling", pinHandle->number);
     if(-1 == epoll_ctl(epoll_descriptor, EPOLL_CTL_DEL, pinHandle->valueFD, NULL)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Del value file of pin %d to polling failed", pinHandle->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Del value file of pin %d to polling failed. %s", pinHandle->number, strerror(errno));
         return JAVACALL_DIO_FAIL;
     };
     pinCountForPolling--;
@@ -963,7 +954,7 @@
     char nameBuffer[VALUE_FILENAME_MAX_LENGTH];
 
     if(JAVACALL_DIO_OK != determine_name_of_value_file(handle, nameBuffer)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not fill valueFD for pin %d. Operation failed", handle->number);
+        JAVACALL_REPORT_WARN1(JC_DIO, "Can not fill valueFD for pin %d. Operation failed", handle->number);
         return JAVACALL_DIO_FAIL;
     }
 
@@ -973,7 +964,7 @@
     drop_privileges();
 
     if(-1 == handle->valueFD) {
-        JAVACALL_REPORT_ERROR(JC_DIO, "Can not open file %s for read value from GPIO pin");
+        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not open file %s for read value from GPIO pin. %s", strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
     return JAVACALL_DIO_OK;
@@ -994,7 +985,7 @@
         }
 
         if(JAVACALL_DIO_OK != activate_platform_notifications_to_pin(pin)) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Platform notifications for pin %d cannot be enabled", pin->number);
+            //activate_platform_notifications_to_pin print error messages
             return JAVACALL_DIO_FAIL;
         }
 
@@ -1020,7 +1011,7 @@
             epoll_descriptor = epoll_create(17);
         }
         if(-1 == epoll_ctl(epoll_descriptor, EPOLL_CTL_ADD, pin->valueFD, new_event)) {
-            JAVACALL_REPORT_ERROR1(JC_DIO, "Add value file of pin %d to polling failed", pin->number);
+            JAVACALL_REPORT_ERROR2(JC_DIO, "Add value file of pin %d to polling failed. %s", pin->number, strerror(errno));
             javacall_free(new_event);
             javacall_free(poll_data);
             success = JAVACALL_FALSE;
@@ -1075,12 +1066,12 @@
     drop_privileges();
 
     if(-1 == edgeFD) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can open edge file for pin %d", pin->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can open edge file for pin %d. %s", pin->number, strerror(errno));
         return JAVACALL_DIO_FAIL;
     }
     get_platform_edge_string(pin->edgeMode, &platformValue);
     if(-1 == write(edgeFD, platformValue, strlen(platformValue) + 1)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "Can not set notifications to edge file for pin %d", pin->number);
+        JAVACALL_REPORT_ERROR2(JC_DIO, "Can not set notifications to edge file for pin %d. %s", pin->number, strerror(errno));
         close(edgeFD);
         return JAVACALL_DIO_FAIL;
     }