From patchwork Mon Jun 19 06:01:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 777581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wrgPp2PKhz9s7m for ; Mon, 19 Jun 2017 16:03:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AQ0zhj99"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wrgPp14MTzDqDF for ; Mon, 19 Jun 2017 16:03:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AQ0zhj99"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wrgPK13w2zDqMP for ; Mon, 19 Jun 2017 16:02:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AQ0zhj99"; dkim-atps=neutral Received: by mail-pg0-x243.google.com with SMTP id f127so14198834pgc.2 for ; Sun, 18 Jun 2017 23:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TVuCixNaaiuOLlZKQCExXgFVqte87zjhgNWiJULbePg=; b=AQ0zhj996c+TfGq82AUCg+tYyKL2dR8jxOYZaQx9xsI3er4PaTrgeBQ6hXsa9+pWkH GpaCy07Zw0PXBSuaVb0eIxo2fnaUzOFCZkxkLiGeVBwlXbiayW6fa9k+uDbMLk2cPtyp nRtcRwzWTdODMMmWkzFNZp+TuhCRB15/AkAQYlAvGvZw6VE+3QBC0hASjz6Bfz08z8gl RpT32ZgaMtuOXuVpxUU+IyhyCXJ9jZz9gY4//TckcXNTsaKc4d4gTq0ERb2fgswAeOGr Z7XbI0S7xPB8Ku9/wieOQwMFzBYGSpYoq3PbrPsBIGCu/AnldvaT746xVdNUXZqYO40z +tOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TVuCixNaaiuOLlZKQCExXgFVqte87zjhgNWiJULbePg=; b=ErTCD8mFb6opMfeRwTe/V12THox6VBUvvlmxIpGuX3pn87mpI/d3sVdp6PoSha5H5u jHOF/ZSE0b+44WR2zD7pT9o1ntLOq67FLdhzJwETW1DL8vibNLy2+MRV4qfBY1pF9veh doFRBY1Ls3Nlp2a9Ut5caYZqIXijlbt7zk6n4F2QyCR3UHR01P0xbdDwl2rq8NJaDNiM NPEZOV+s+EeyAoXjwyjk7Db6SYORaWLQ9zR/LvfQIOCZ/Z4Uje7GPzJUq399mwee1Z+z eECkZpsUMF3amkMpaRTg/2MzXNtmp7Iicdi/CwAE6mHjPFCtQMyyKX2A/AyAYg4dxmOP RT5Q== X-Gm-Message-State: AKS2vOyiMU3V1JuyKbAq4baF8VpWo6H1xES4cEc7QzT5ITLPYIIyS1Cc 64ZtECXSzFlqF47o X-Received: by 10.99.143.9 with SMTP id n9mr24643641pgd.145.1497852163098; Sun, 18 Jun 2017 23:02:43 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x64sm19638626pff.123.2017.06.18.23.02.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 23:02:42 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Mon, 19 Jun 2017 16:01:36 +1000 Message-Id: <20170619060138.5314-4-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170619060138.5314-1-oohall@gmail.com> References: <20170619060138.5314-1-oohall@gmail.com> Subject: [Skiboot] [PATCH 4/6] core/test: add a console flushing test X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Adds a test to verify that flushing the console buffer works properly. Signed-off-by: Oliver O'Halloran --- core/test/Makefile.check | 1 + core/test/run-console-flush.c | 130 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 core/test/run-console-flush.c diff --git a/core/test/Makefile.check b/core/test/Makefile.check index 813bd0207d8c..630de2e4ca36 100644 --- a/core/test/Makefile.check +++ b/core/test/Makefile.check @@ -2,6 +2,7 @@ CORE_TEST := \ core/test/run-bitmap \ core/test/run-device \ + core/test/run-console-flush \ core/test/run-flash-subpartition \ core/test/run-mem_region \ core/test/run-malloc \ diff --git a/core/test/run-console-flush.c b/core/test/run-console-flush.c new file mode 100644 index 000000000000..33db0460da8f --- /dev/null +++ b/core/test/run-console-flush.c @@ -0,0 +1,130 @@ +/* Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define __TEST__ +#define _printf printf + +/* fake out the timebase sett */ +unsigned long tb_hz = 512000000; + +static inline unsigned long mftb(void) +{ + return 0; +} + +int _printf(const char *fmt, ...); + +static struct debug_descriptor debug_descriptor; + +#include "../console.c" +#include "../console-log.c" + +int flush_buffer_offset = 0; +static bool flushed_to_drivers = false; +static char flush_buffer[65536]; +static char console_buffer[65536]; + +/* + * Inside skiboot we have our own write() function that breaks + * the normal stdlib write(). We can use writev() instead though + */ +static size_t unix_write(int fd, const char *buf, size_t len) +{ + struct iovec iov = {(void *)buf, len}; + + return writev(fd, &iov, 1); +} + +/* For debugging I usually hack in some mambo_printfs + * this implements the backend for the test */ +size_t mambo_console_write(const char *buf, size_t count) +{ + return unix_write(2, buf, count); +} + +static size_t flush_write(const char *buf, size_t len) +{ + memcpy(flush_buffer + flush_buffer_offset, buf, len); + + flush_buffer_offset += len; + flush_buffer_offset %= sizeof(flush_buffer); + + return len; +} + +static struct con_ops unix_con = { + .write = flush_write, +}; + +static void populate_console(int mem_lvl, int flush_lvl) +{ + int i; + + memset(console_buffer, 0, sizeof(console_buffer)); + con_in = 0; + con_out = 0; + + debug_descriptor.console_log_levels = (mem_lvl << 4) | flush_lvl; + + for (i = 0; i < 20; i++) + prlog(i % (PR_INSANE + 1), "Hello World! %d\r\n", i); +} + +int main(void) +{ + int ret; + + this_cpu()->con_suspend = false; + set_console(&unix_con); + + /* fix up the console globals */ + flushed_to_drivers = false; + con_buf = console_buffer; + memcons.obuf_phys = (uint64_t) console_buffer; + memcons.obuf_size = sizeof(console_buffer); + + populate_console(PR_INSANE, PR_NOTICE); + __flush_console(true); + + /* + * Refill the console buffer dropping everything above PR_NOTICE + * The contents of the flushed and the refilled buffer should + * be identical. + */ + set_console(NULL); /* prevent writes into flush_buffer */ + populate_console(PR_NOTICE, 0); + + ret = memcmp(flush_buffer, console_buffer, con_in); + if (ret) { + unix_write(2, "=========\n", sizeof("=========\n") - 1); + unix_write(2, console_buffer, strlen(console_buffer)); + unix_write(2, "=========\n", sizeof("=========\n") - 1); + unix_write(2, flush_buffer, strlen(flush_buffer)); + } + + return ret; +}