+kern_return_t
+console_serial_alloc_rel_tests(void)
+{
+ unsigned long i, free_buf_count = 0;
+ uint32_t * p;
+ console_buf_t * cbp;
+ thread_t thread;
+ kern_return_t kr;
+
+ T_LOG("doing alloc/release tests");
+
+ for (i = 0; i < MAX_CPU_SLOTS; i++) {
+ p = (uint32_t *)((uintptr_t)console_ring.buffer + console_ring.len + (i * sizeof(console_buf_t)));
+ cbp = (console_buf_t *)(void *)p;
+ /* p should either be allocated cpu buffer or have CPU_BUF_FREE_HEX in it */
+ T_ASSERT(*p == CPU_BUF_FREE_HEX || cbp->buf_base == &cbp->buf[0], "");
+ if (*p == CPU_BUF_FREE_HEX) {
+ free_buf_count++;
+ }
+ }
+
+ T_ASSERT_GE_ULONG(free_buf_count, 2, "At least 2 buffers should be free");
+ cons_test_ops_count = 0;
+
+ kr = kernel_thread_start(alloc_free_func, (void *)1000, &thread);
+ T_ASSERT_EQ_INT(kr, KERN_SUCCESS, "kernel_thread_start returned successfully");
+
+ /* yeild cpu to give other thread chance to get on-core */
+ delay(100);
+
+ alloc_free_func((void *)1000, 0);
+
+ /* wait until other thread finishes its tasks */
+ while (cons_test_ops_count < 2000) {
+ delay(1000);
+ }
+
+ thread_deallocate(thread);
+ /* verify again that atleast 2 slots are free */
+ free_buf_count = 0;
+ for (i = 0; i < MAX_CPU_SLOTS; i++) {
+ p = (uint32_t *)((uintptr_t)console_ring.buffer + console_ring.len + (i * sizeof(console_buf_t)));
+ cbp = (console_buf_t *)(void *)p;
+ /* p should either be allocated cpu buffer or have CPU_BUF_FREE_HEX in it */
+ T_ASSERT(*p == CPU_BUF_FREE_HEX || cbp->buf_base == &cbp->buf[0], "");
+ if (*p == CPU_BUF_FREE_HEX) {
+ free_buf_count++;
+ }
+ }
+ T_ASSERT_GE_ULONG(free_buf_count, 2, "At least 2 buffers should be free after alloc free tests");
+
+ return KERN_SUCCESS;
+}
+
+kern_return_t
+console_serial_test(void)
+{
+ unsigned long i;
+ char buffer[CPU_BUFFER_LEN];
+ uint32_t * p;
+ console_buf_t * cbp;
+
+ T_LOG("Checking console_ring status.");
+ T_ASSERT_EQ_INT(console_ring.len, KERN_CONSOLE_RING_SIZE, "Console ring size is not correct.");
+ T_ASSERT_GT_INT(KERN_CONSOLE_BUF_SIZE, KERN_CONSOLE_RING_SIZE, "kernel console buffer size is < allocation.");
+
+ /* select the next slot from the per cpu buffers at end of console_ring.buffer */
+ for (i = 0; i < MAX_CPU_SLOTS; i++) {
+ p = (uint32_t *)((uintptr_t)console_ring.buffer + console_ring.len + (i * sizeof(console_buf_t)));
+ cbp = (console_buf_t *)(void *)p;
+ /* p should either be allocated cpu buffer or have CPU_BUF_FREE_HEX in it */
+ T_ASSERT(*p == CPU_BUF_FREE_HEX || cbp->buf_base == &cbp->buf[0], "verified initialization of cpu buffers p=%p", (void *)p);
+ }
+
+ /* setup buffer to be chars */
+ for (i = 0; i < CPU_BUFFER_LEN; i++) {
+ buffer[i] = (char)('0' + (i % 10));
+ }
+ buffer[CPU_BUFFER_LEN - 1] = '\0';
+
+ T_LOG("Printing %d char string to serial one char at a time.", CPU_BUFFER_LEN);
+ for (i = 0; i < CPU_BUFFER_LEN; i++) {
+ printf("%c", buffer[i]);
+ }
+ printf("End\n");
+ T_LOG("Printing %d char string to serial as a whole", CPU_BUFFER_LEN);
+ printf("%s\n", buffer);
+
+ T_LOG("Using console_write call repeatedly for 100 iterations");
+ for (i = 0; i < 100; i++) {
+ console_write(&buffer[0], 14);
+ if ((i % 6) == 0) {
+ printf("\n");
+ }
+ }
+ printf("\n");
+
+ T_LOG("Using T_LOG to print buffer %s", buffer);
+ return KERN_SUCCESS;
+}
+#endif