Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: blinky_max32630fthr
TESTS/mbed_drivers/dev_null/main.cpp@0:5c4d7b2438d3, 2016-11-11 (annotated)
- Committer:
- switches
- Date:
- Fri Nov 11 20:59:50 2016 +0000
- Revision:
- 0:5c4d7b2438d3
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| switches | 0:5c4d7b2438d3 | 1 | /* mbed Microcontroller Library |
| switches | 0:5c4d7b2438d3 | 2 | * Copyright (c) 2013-2014 ARM Limited |
| switches | 0:5c4d7b2438d3 | 3 | * |
| switches | 0:5c4d7b2438d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| switches | 0:5c4d7b2438d3 | 5 | * you may not use this file except in compliance with the License. |
| switches | 0:5c4d7b2438d3 | 6 | * You may obtain a copy of the License at |
| switches | 0:5c4d7b2438d3 | 7 | * |
| switches | 0:5c4d7b2438d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| switches | 0:5c4d7b2438d3 | 9 | * |
| switches | 0:5c4d7b2438d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
| switches | 0:5c4d7b2438d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| switches | 0:5c4d7b2438d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| switches | 0:5c4d7b2438d3 | 13 | * See the License for the specific language governing permissions and |
| switches | 0:5c4d7b2438d3 | 14 | * limitations under the License. |
| switches | 0:5c4d7b2438d3 | 15 | */ |
| switches | 0:5c4d7b2438d3 | 16 | |
| switches | 0:5c4d7b2438d3 | 17 | #include "mbed.h" |
| switches | 0:5c4d7b2438d3 | 18 | #include "greentea-client/test_env.h" |
| switches | 0:5c4d7b2438d3 | 19 | |
| switches | 0:5c4d7b2438d3 | 20 | class DevNull : public Stream { |
| switches | 0:5c4d7b2438d3 | 21 | public: |
| switches | 0:5c4d7b2438d3 | 22 | DevNull(const char *name = NULL) : Stream(name) {} |
| switches | 0:5c4d7b2438d3 | 23 | |
| switches | 0:5c4d7b2438d3 | 24 | protected: |
| switches | 0:5c4d7b2438d3 | 25 | virtual int _getc() { |
| switches | 0:5c4d7b2438d3 | 26 | return 0; |
| switches | 0:5c4d7b2438d3 | 27 | } |
| switches | 0:5c4d7b2438d3 | 28 | virtual int _putc(int c) { |
| switches | 0:5c4d7b2438d3 | 29 | return c; |
| switches | 0:5c4d7b2438d3 | 30 | } |
| switches | 0:5c4d7b2438d3 | 31 | }; |
| switches | 0:5c4d7b2438d3 | 32 | |
| switches | 0:5c4d7b2438d3 | 33 | DevNull null("null"); |
| switches | 0:5c4d7b2438d3 | 34 | |
| switches | 0:5c4d7b2438d3 | 35 | int main() { |
| switches | 0:5c4d7b2438d3 | 36 | GREENTEA_SETUP(2, "dev_null_auto"); |
| switches | 0:5c4d7b2438d3 | 37 | |
| switches | 0:5c4d7b2438d3 | 38 | printf("MBED: before re-routing stdout to /null\n"); // This shouldn't appear |
| switches | 0:5c4d7b2438d3 | 39 | greentea_send_kv("to_stdout", "re-routing stdout to /null"); |
| switches | 0:5c4d7b2438d3 | 40 | |
| switches | 0:5c4d7b2438d3 | 41 | if (freopen("/null", "w", stdout)) { |
| switches | 0:5c4d7b2438d3 | 42 | // This shouldn't appear on serial |
| switches | 0:5c4d7b2438d3 | 43 | // We should use pure printf here to send KV |
| switches | 0:5c4d7b2438d3 | 44 | printf("{{to_null;printf redirected to /null}}\n"); |
| switches | 0:5c4d7b2438d3 | 45 | printf("MBED: this printf is already redirected to /null\n"); |
| switches | 0:5c4d7b2438d3 | 46 | } |
| switches | 0:5c4d7b2438d3 | 47 | |
| switches | 0:5c4d7b2438d3 | 48 | while(1) { |
| switches | 0:5c4d7b2438d3 | 49 | // Success is determined by the host test at this point, so busy wait |
| switches | 0:5c4d7b2438d3 | 50 | } |
| switches | 0:5c4d7b2438d3 | 51 | } |